nvwa::fixed_mem_pool< _Tp > Class Template Reference

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

#include <fixed_mem_pool.h>

Collaboration diagram for nvwa::fixed_mem_pool< _Tp >:
Collaboration graph
[legend]

List of all members.

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

Public Types

typedef class_level_lock
< fixed_mem_pool< _Tp >
>::lock 
lock

Static Public Member Functions

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

Static Protected Member Functions

static bool bad_alloc_handler ()
 Bad allocation handler.

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:
_Tp class to use the fixed_mem_pool

Member Typedef Documentation

template<class _Tp >
typedef class_level_lock<fixed_mem_pool<_Tp> >::lock nvwa::fixed_mem_pool< _Tp >::lock

Member Function Documentation

template<class _Tp >
void * nvwa::fixed_mem_pool< _Tp >::allocate (  )  [inline, static]

Allocates a memory block from the memory pool.

Returns:
pointer to the allocated memory block
template<class _Tp >
bool nvwa::fixed_mem_pool< _Tp >::bad_alloc_handler (  )  [inline, static, protected]

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.

template<class _Tp >
void nvwa::fixed_mem_pool< _Tp >::deallocate ( void *  block_ptr  )  [inline, static]

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

Parameters:
block_ptr pointer to the memory block to return
template<class _Tp >
int nvwa::fixed_mem_pool< _Tp >::deinitialize (  )  [inline, 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
template<class _Tp >
int nvwa::fixed_mem_pool< _Tp >::get_alloc_count (  )  [inline, static]

Gets the allocation count.

Returns:
the number of memory blocks still in allocation
template<class _Tp >
bool nvwa::fixed_mem_pool< _Tp >::initialize ( size_t  size  )  [inline, static]

Initializes the memory pool.

Parameters:
size number of memory blocks to put in the memory pool
Returns:
true if successful; false if memory insufficient
template<class _Tp >
bool nvwa::fixed_mem_pool< _Tp >::is_initialized (  )  [inline, static]

Is the memory pool initialized?

Returns:
true if it is successfully initialized; false otherwise

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines

Generated by  doxygen 1.6.2