PUMA Library Reference Manual
Puma::MemPool Class Reference

#include <Puma/MemPool.h>

+ Inheritance diagram for Puma::MemPool:


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.

This class is not used and may disappear without notice.

Public Member Functions

 MemPool (unsigned long blocksize=128L *1024L)
 Construct a new memory pool. More...
 ~MemPool ()
 Destroy the pool. More...
void * alloc (unsigned long objectsize)
 Allocate memory for a new object of a given size. More...
void dealloc (void *pointer)
 De-allocate memory for a new object. More...
void free ()
 Free all the allocated memory in this pool. More...

Additional Inherited Members

- Protected Member Functions inherited from Puma::Heap
 Heap ()
 Constructor. More...
 ~Heap ()
 Destructor. More...
void * malloc (size_t n)
 Allocate n bytes of memory. More...
void free (void *p)
 Free the given memory. More...

Constructor & Destructor Documentation

◆ MemPool()

Puma::MemPool::MemPool ( unsigned long  blocksize = 128L *1024L)

Construct a new memory pool.

blocksizeSize of a memory block. Defaults to 128 KB.

◆ ~MemPool()

Puma::MemPool::~MemPool ( )

Destroy the pool.

Frees the allocated memory.

Member Function Documentation

◆ alloc()

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.

objectsizeThe size of the object in bytes.
The allocated memory.

◆ dealloc()

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.

pointerPointer to the chunk of memory to de-allocate.

◆ free()

void Puma::MemPool::free ( )

Free all the allocated memory in this pool.