#include "CAutoMemoryPool.h" using namespace std; int main() { CAutoMemoryPool Pmp(16 * 1024); // create a memory pool with 16KB capacity return 0; }
#include "CAutoMemoryPool.h" using namespace std; int main() { CAutoMemoryPool Pmp(16 * 1024); // create a memory pool with 16KB capacity void* ptr = Pmp.Alloc(100); // allocate 100 bytes from the memory pool return 0; }
#include "CAutoMemoryPool.h" using namespace std; int main() { CAutoMemoryPool Pmp(16 * 1024); // create a memory pool with 16KB capacity void* ptr = Pmp.Alloc(100); // allocate 100 bytes from the memory pool Pmp.Free(ptr); // deallocate the memory block return 0; }
#include "CAutoMemoryPool.h" using namespace std; class MyClass { public: int x, y; }; int main() { CAutoMemoryPool Pmp(16 * 1024); // create a memory pool with 16KB capacity MyClass* arr = (MyClass*)Pmp.Alloc(sizeof(MyClass) * 10); // allocate an array of 10 MyClass objects from the memory pool return 0; }The package library that contains the CAutoMemoryPool class is most likely a custom library developed by the author of the code examples. There are, however, similar memory pool libraries available in popular C++ libraries such as Boost and the STL.