PUMA Library Reference Manual
Puma::ConstSizeMemPool< N > Class Template Reference

#include <Puma/ConstSizeMemPool.h>

Description

template<int N>
class Puma::ConstSizeMemPool< N >

Constant size memory block pool. Memory blocks are not freed before the pool is destroyed. Free blocks are inserted into a free list for reuse.

Following global functions are defined that use a constant size memory pool:

Template Parameters
NNumber of bytes for each memory block to allocate.

Public Member Functions

 ConstSizeMemPool ()
 Construct an empty memory pool. More...
 
 ~ConstSizeMemPool ()
 Destroy the memory pool. More...
 
void * alloc ()
 Get a block of memory. More...
 
void free (void *block)
 Insert a block of memory into the free list for reuse. More...
 
void clean ()
 Free all allocated memory blocks. More...
 

Static Public Member Functions

static ConstSizeMemPoolinst ()
 Get the memory pool for this block size. More...
 

Constructor & Destructor Documentation

◆ ConstSizeMemPool()

template<int N>
Puma::ConstSizeMemPool< N >::ConstSizeMemPool ( )
inline

Construct an empty memory pool.

◆ ~ConstSizeMemPool()

template<int N>
Puma::ConstSizeMemPool< N >::~ConstSizeMemPool ( )
inline

Destroy the memory pool.

Frees all memory blocks allocated.

Member Function Documentation

◆ alloc()

template<int N>
void * Puma::ConstSizeMemPool< N >::alloc ( )
inline

Get a block of memory.

If no free block is available, a new block of memory is allocated.

Returns
Pointer to the block of memory.

◆ clean()

template<int N>
void Puma::ConstSizeMemPool< N >::clean ( )
inline

Free all allocated memory blocks.

◆ free()

template<int N>
void Puma::ConstSizeMemPool< N >::free ( void *  block)
inline

Insert a block of memory into the free list for reuse.

The memory block is freed when the pool is destroyed.

Parameters
blockPointer to the memory block.

◆ inst()

template<int N>
static ConstSizeMemPool& Puma::ConstSizeMemPool< N >::inst ( )
inlinestatic

Get the memory pool for this block size.

There is only one memory pool for each block size.

Returns
A reference to the memory pool.