PUMA Library Reference Manual
Loading...
Searching...
No Matches
Puma::MemPool Class Reference

#include <Puma/MemPool.h>

+ Inheritance diagram for Puma::MemPool:

Description

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.

Warning
This class is not used and may disappear without notice.

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.
 

Constructor & Destructor Documentation

◆ MemPool()

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

Construct a new memory pool.

Parameters
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.

Parameters
objectsizeThe size of the object in bytes.
Returns
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.

Parameters
pointerPointer to the chunk of memory to de-allocate.

◆ free()

void Puma::MemPool::free ( )

Free all the allocated memory in this pool.