PUMA Library Reference Manual
|
#include <Puma/MemPool.h>
Memory pool implementation based on a linked list of memory blocks.
Allocates large blocks of memory to reduce the overhead of memory allocation when a lot of small objects need to be allocated. Does not free any allocated memory until the pool is destroyed.
Public Member Functions | |
MemPool (unsigned long blocksize=128L *1024L) | |
Construct a new memory pool. | |
~MemPool () | |
Destroy the pool. | |
void * | alloc (unsigned long objectsize) |
Allocate memory for a new object of a given size. | |
void | dealloc (void *pointer) |
De-allocate memory for a new object. | |
void | free () |
Free all the allocated memory in this pool. | |
Additional Inherited Members | |
Protected Member Functions inherited from Puma::Heap | |
Heap () | |
Constructor. | |
~Heap () | |
Destructor. | |
void * | malloc (size_t n) |
Allocate n bytes of memory. | |
void | free (void *p) |
Free the given memory. | |
Puma::MemPool::MemPool | ( | unsigned long | blocksize = 128L *1024L | ) |
Construct a new memory pool.
blocksize | Size of a memory block. Defaults to 128 KB. |
Puma::MemPool::~MemPool | ( | ) |
Destroy the pool.
Frees the allocated memory.
void * Puma::MemPool::alloc | ( | unsigned long | objectsize | ) |
Allocate memory for a new object of a given size.
Usually no new memory needs to be allocated, but a chunk of previously allocated memory is returned.
objectsize | The size of the object in bytes. |
void Puma::MemPool::dealloc | ( | void * | pointer | ) |
De-allocate memory for a new object.
Since no memory is freed until the pool is destroyed, this method does nothing.
pointer | Pointer to the chunk of memory to de-allocate. |
void Puma::MemPool::free | ( | ) |
Free all the allocated memory in this pool.