Singleton class template to manage the allocation/deallocation of memory blocks of one specific size. More...
#include <static_mem_pool.h>
Public Member Functions | |
void * | allocate () |
Allocates memory and returns its pointer. | |
void | deallocate (void *ptr) |
Deallocates memory by putting the memory block into the pool. | |
virtual void | recycle () |
Recycles half of the free memory blocks in the memory pool to the system. | |
Static Public Member Functions | |
static static_mem_pool & | instance () |
Gets the instance of the static memory pool. | |
static static_mem_pool & | instance_known () |
Gets the known instance of the static memory pool. |
Singleton class template to manage the allocation/deallocation of memory blocks of one specific size.
_Sz | size of elements in the static_mem_pool | |
_Gid | group ID of a static_mem_pool: if it is negative, simultaneous accesses to this static_mem_pool will be protected from each other; otherwise no protection is given |
void* nvwa::static_mem_pool< _Sz, _Gid >::allocate | ( | ) | [inline] |
Allocates memory and returns its pointer.
The template will try to get it from the memory pool first, and request memory from the system if there is no free memory in the pool.
NULL
otherwise void nvwa::static_mem_pool< _Sz, _Gid >::deallocate | ( | void * | ptr | ) | [inline] |
Deallocates memory by putting the memory block into the pool.
ptr | pointer to memory to be deallocated |
static static_mem_pool& nvwa::static_mem_pool< _Sz, _Gid >::instance | ( | ) | [inline, static] |
Gets the instance of the static memory pool.
It will create the instance if it does not already exist. Generally this function is now not needed.
static static_mem_pool& nvwa::static_mem_pool< _Sz, _Gid >::instance_known | ( | ) | [inline, static] |
Gets the known instance of the static memory pool.
The instance must already exist. Generally the static initializer of the template guarantees it.
void nvwa::static_mem_pool< _Sz, _Gid >::recycle | ( | ) | [inline, virtual] |
Recycles half of the free memory blocks in the memory pool to the system.
It is called when a memory request to the system (in other instances of the static memory pool) fails.
Implements nvwa::mem_pool_base.