Nvwa  1.1
Public Member Functions | Static Public Member Functions | List of all members
nvwa::static_mem_pool< _Sz, _Gid > Class Template Reference

Singleton class template to manage the allocation/deallocation of memory blocks of one specific size. More...

#include <static_mem_pool.h>

Inheritance diagram for nvwa::static_mem_pool< _Sz, _Gid >:
[legend]
Collaboration diagram for nvwa::static_mem_pool< _Sz, _Gid >:
[legend]

Public Member Functions

void * allocate ()
 Allocates memory and returns its pointer. More...
 
void deallocate (void *ptr)
 Deallocates memory by putting the memory block into the pool. More...
 
virtual void recycle () override
 Recycles half of the free memory blocks in the memory pool to the system. More...
 
- Public Member Functions inherited from nvwa::mem_pool_base
virtual ~mem_pool_base ()
 Empty base destructor.
 

Static Public Member Functions

static static_mem_poolinstance ()
 Gets the instance of the static memory pool. More...
 
static static_mem_poolinstance_known ()
 Gets the known instance of the static memory pool. More...
 
- Static Public Member Functions inherited from nvwa::mem_pool_base
static void * alloc_sys (size_t size)
 Allocates memory from the run-time system. More...
 
static void dealloc_sys (void *ptr)
 Frees memory and returns it to the run-time system. More...
 

Detailed Description

template<size_t _Sz, int _Gid = -1>
class nvwa::static_mem_pool< _Sz, _Gid >

Singleton class template to manage the allocation/deallocation of memory blocks of one specific size.

Parameters
_Szsize of elements in the static_mem_pool
_Gidgroup 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

Member Function Documentation

◆ allocate()

template<size_t _Sz, int _Gid = -1>
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.

Returns
pointer to allocated memory if successful; null otherwise

◆ deallocate()

template<size_t _Sz, int _Gid = -1>
void nvwa::static_mem_pool< _Sz, _Gid >::deallocate ( void *  ptr)
inline

Deallocates memory by putting the memory block into the pool.

Parameters
ptrpointer to memory to be deallocated

◆ instance()

template<size_t _Sz, int _Gid = -1>
static static_mem_pool& nvwa::static_mem_pool< _Sz, _Gid >::instance ( )
inlinestatic

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.

Returns
reference to the instance of the static memory pool
See also
instance_known

◆ instance_known()

template<size_t _Sz, int _Gid = -1>
static static_mem_pool& nvwa::static_mem_pool< _Sz, _Gid >::instance_known ( )
inlinestatic

Gets the known instance of the static memory pool.

The instance must already exist. Generally the static initializer of the template guarantees it.

Returns
reference to the instance of the static memory pool

◆ recycle()

template<size_t _Sz, int _Gid>
void nvwa::static_mem_pool< _Sz, _Gid >::recycle ( )
overridevirtual

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.


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