Nvwa  1.1
Classes | Static Public Member Functions | Static Protected Member Functions | Static Private Attributes | List of all members
nvwa::fixed_mem_pool< _Tp > Class Template Reference

Class template to manipulate a fixed-size memory pool. More...

#include <fixed_mem_pool.h>

Classes

struct  alignment
 Specializable struct to define the alignment of an object in the fixed_mem_pool. More...
 
struct  block_size
 Struct to calculate the block size based on the (specializable) alignment value. More...
 

Static Public Member Functions

static void * allocate ()
 Allocates a memory block from the memory pool. More...
 
static void deallocate (void *)
 Deallocates a memory block and returns it to the memory pool. More...
 
static bool initialize (size_t size)
 Initializes the memory pool. More...
 
static int deinitialize ()
 Deinitializes the memory pool. More...
 
static int get_alloc_count ()
 Gets the allocation count. More...
 
static bool is_initialized ()
 Is the memory pool initialized? More...
 

Static Protected Member Functions

static bool bad_alloc_handler ()
 Bad allocation handler. More...
 

Static Private Attributes

static void * _S_mem_pool_ptr = nullptr
 Pointer to the allocated chunk of memory. More...
 
static void * _S_first_avail_ptr = nullptr
 Pointer to the first available memory block. More...
 
static int _S_alloc_cnt = 0
 Count of allocations. More...
 

Detailed Description

template<class _Tp>
class nvwa::fixed_mem_pool< _Tp >

Class template to manipulate a fixed-size memory pool.

Please notice that only allocate and deallocate are protected by a lock.

Parameters
_Tpclass to use the fixed_mem_pool

Member Function Documentation

◆ allocate()

template<class _Tp >
void * nvwa::fixed_mem_pool< _Tp >::allocate ( )
inlinestatic

Allocates a memory block from the memory pool.

Returns
pointer to the allocated memory block

◆ bad_alloc_handler()

template<class _Tp >
bool nvwa::fixed_mem_pool< _Tp >::bad_alloc_handler ( )
staticprotected

Bad allocation handler.

Called when there are no memory blocks available in the memory pool. If this function returns false (default behaviour if not explicitly specialized), it indicates that it can do nothing and allocate() should return null; if this function returns true, it indicates that it has freed some memory blocks and allocate() should try allocating again.

◆ deallocate()

template<class _Tp >
void nvwa::fixed_mem_pool< _Tp >::deallocate ( void *  block_ptr)
inlinestatic

Deallocates a memory block and returns it to the memory pool.

Parameters
block_ptrpointer to the memory block to return

◆ deinitialize()

template<class _Tp >
int nvwa::fixed_mem_pool< _Tp >::deinitialize ( )
static

Deinitializes the memory pool.

Returns
0 if all memory blocks are returned and the memory pool successfully freed; or a non-zero value indicating number of memory blocks still in allocation

◆ get_alloc_count()

template<class _Tp >
int nvwa::fixed_mem_pool< _Tp >::get_alloc_count ( )
inlinestatic

Gets the allocation count.

Returns
the number of memory blocks still in allocation

◆ initialize()

template<class _Tp >
bool nvwa::fixed_mem_pool< _Tp >::initialize ( size_t  size)
static

Initializes the memory pool.

Parameters
sizenumber of memory blocks to put in the memory pool
Returns
true if successful; false if memory insufficient

◆ is_initialized()

template<class _Tp >
bool nvwa::fixed_mem_pool< _Tp >::is_initialized ( )
inlinestatic

Is the memory pool initialized?

Returns
true if it is successfully initialized; false otherwise

Member Data Documentation

◆ _S_alloc_cnt

template<class _Tp >
int nvwa::fixed_mem_pool< _Tp >::_S_alloc_cnt = 0
staticprivate

Count of allocations.

◆ _S_first_avail_ptr

template<class _Tp >
void * nvwa::fixed_mem_pool< _Tp >::_S_first_avail_ptr = nullptr
staticprivate

Pointer to the first available memory block.

◆ _S_mem_pool_ptr

template<class _Tp >
void * nvwa::fixed_mem_pool< _Tp >::_S_mem_pool_ptr = nullptr
staticprivate

Pointer to the allocated chunk of memory.


The documentation for this class was generated from the following file: