QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
qx::memory::static_mem_pool< _Sz, _Gid > Class Template Reference

#include <static_mem_pool.h>

Inheritance diagram for qx::memory::static_mem_pool< _Sz, _Gid >:
qx::memory::mem_pool_base

Public Member Functions

void * allocate ()
 
void deallocate (void *__ptr)
 
virtual void recycle ()
 
- Public Member Functions inherited from qx::memory::mem_pool_base
virtual ~mem_pool_base ()
 

Static Public Member Functions

static static_mem_poolinstance ()
 
static static_mem_poolinstance_known ()
 
- Static Public Member Functions inherited from qx::memory::mem_pool_base
static void * alloc_sys (size_t __size)
 
static void dealloc_sys (void *__ptr)
 

Private Types

typedef class_level_lock< static_mem_pool< _Sz, _Gid >,(_Gid< 0)>::lock lock
 

Private Member Functions

 static_mem_pool ()
 
 ~static_mem_pool ()
 
 static_mem_pool (const static_mem_pool &)
 
const static_mem_pooloperator= (const static_mem_pool &)
 

Static Private Member Functions

static size_t _S_align (size_t __size)
 
static void * _S_alloc_sys (size_t __size)
 
static static_mem_pool_S_create_instance ()
 

Static Private Attributes

static bool _S_destroyed = false
 
static static_mem_pool_S_instance_p = _S_create_instance()
 
static mem_pool_base::_Block_list_S_memory_block_p = NULL
 

Detailed Description

template<size_t _Sz, int _Gid = -1>
class qx::memory::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

Definition at line 124 of file static_mem_pool.h.

Member Typedef Documentation

◆ lock

template<size_t _Sz, int _Gid = -1>
typedef class_level_lock<static_mem_pool<_Sz,_Gid>,(_Gid<0)>::lock qx::memory::static_mem_pool< _Sz, _Gid >::lock
private

Definition at line 127 of file static_mem_pool.h.

Constructor & Destructor Documentation

◆ static_mem_pool() [1/2]

template<size_t _Sz, int _Gid = -1>
qx::memory::static_mem_pool< _Sz, _Gid >::static_mem_pool ( )
inlineprivate

Definition at line 195 of file static_mem_pool.h.

◆ ~static_mem_pool()

template<size_t _Sz, int _Gid = -1>
qx::memory::static_mem_pool< _Sz, _Gid >::~static_mem_pool ( )
inlineprivate

Definition at line 200 of file static_mem_pool.h.

◆ static_mem_pool() [2/2]

template<size_t _Sz, int _Gid = -1>
qx::memory::static_mem_pool< _Sz, _Gid >::static_mem_pool ( const static_mem_pool< _Sz, _Gid > & )
private

Member Function Documentation

◆ _S_align()

template<size_t _Sz, int _Gid = -1>
static size_t qx::memory::static_mem_pool< _Sz, _Gid >::_S_align ( size_t __size)
inlinestaticprivate

Definition at line 221 of file static_mem_pool.h.

◆ _S_alloc_sys()

template<size_t _Sz, int _Gid>
void * qx::memory::static_mem_pool< _Sz, _Gid >::_S_alloc_sys ( size_t __size)
staticprivate

Definition at line 276 of file static_mem_pool.h.

◆ _S_create_instance()

template<size_t _Sz, int _Gid>
static_mem_pool< _Sz, _Gid > * qx::memory::static_mem_pool< _Sz, _Gid >::_S_create_instance ( )
staticprivate

Definition at line 289 of file static_mem_pool.h.

◆ allocate()

template<size_t _Sz, int _Gid = -1>
void * qx::memory::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

Definition at line 166 of file static_mem_pool.h.

◆ deallocate()

template<size_t _Sz, int _Gid = -1>
void qx::memory::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

Definition at line 184 of file static_mem_pool.h.

◆ instance()

template<size_t _Sz, int _Gid = -1>
static static_mem_pool & qx::memory::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

Definition at line 137 of file static_mem_pool.h.

◆ instance_known()

template<size_t _Sz, int _Gid = -1>
static static_mem_pool & qx::memory::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

Definition at line 153 of file static_mem_pool.h.

◆ operator=()

template<size_t _Sz, int _Gid = -1>
const static_mem_pool & qx::memory::static_mem_pool< _Sz, _Gid >::operator= ( const static_mem_pool< _Sz, _Gid > & )
private

◆ recycle()

template<size_t _Sz, int _Gid>
void qx::memory::static_mem_pool< _Sz, _Gid >::recycle ( )
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 qx::memory::mem_pool_base.

Definition at line 250 of file static_mem_pool.h.

Member Data Documentation

◆ _S_destroyed

template<size_t _Sz, int _Gid>
bool qx::memory::static_mem_pool< _Sz, _Gid >::_S_destroyed = false
staticprivate

Definition at line 228 of file static_mem_pool.h.

◆ _S_instance_p

template<size_t _Sz, int _Gid>
static_mem_pool< _Sz, _Gid > * qx::memory::static_mem_pool< _Sz, _Gid >::_S_instance_p = _S_create_instance()
staticprivate

Definition at line 229 of file static_mem_pool.h.

◆ _S_memory_block_p

template<size_t _Sz, int _Gid>
mem_pool_base::_Block_list * qx::memory::static_mem_pool< _Sz, _Gid >::_S_memory_block_p = NULL
staticprivate

Definition at line 230 of file static_mem_pool.h.


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