# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

NLMISC::CBlockMemory Class Template Reference

Block memory allocation. More...

#include <block_memory.h>

List of all members.

Public Methods

 CBlockMemory (uint blockSize=16)
 Constructor. More...

 CBlockMemory (const CBlockMemory< T, __ctor_dtor__ > &other)
 ~CBlockMemory ()
 purge(). More...

T * allocate ()
 allocate an element. ctor is called. More...

void free (T *ptr)
 delete an element allocated with this manager. dtor is called. NULL is tested. More...

void purge ()
 delete all blocks, freeing all memory. More...

void __stl_alloc_changeEltSize (uint eltSize)
uint __stl_alloc_getEltSize () const

Private Types

enum  TCheckIdent { CheckAllocatedIdent = 0x01234567, CheckDeletedIdent = 0x89ABCDEF }
 For debug only, check ident. More...


Private Methods

void buildBlock (CBlock &block)
void releaseBlock (CBlock &block)

Private Attributes

uint _BlockSize
 size of a block. More...

uint _EltSize
 size of an element in the block. More...

sint _NAllocatedElts
 number of elements allocated. More...

void * _NextFreeElt
 next free element. More...

std::list< CBlock_Blocks
 list of blocks. More...


Detailed Description

template<class T, bool __ctor_dtor__ = true>
class NLMISC::CBlockMemory< T, __ctor_dtor__ >

Block memory allocation.

This memory manager is a fast memory allocator, doing same thing as new/delete. It works by block. block are always allocated, never deleted. alocation/free are in O(1).

Elements with sizeof(T)<sizeof(void*) should not be used with this allocator, because sizeEltInMemory= max(sizeof(T),sizeof(void*)).

free() check invalid ptr in debug only, for extra cost of 8 octets per element.

NB: if template parameter __ctor_dtor__ is false, then ctor and dtor are not called when an element is allocate()-ed or deallocate()-ed.

Author:
Lionel Berenguier , Nevrax France
Date:
2001

Definition at line 64 of file block_memory.h.


Member Enumeration Documentation

template<class T, bool __ctor_dtor__ = true>
enum NLMISC::CBlockMemory::TCheckIdent [private]
 

For debug only, check ident.

Enumeration values:
CheckAllocatedIdent 
CheckDeletedIdent 

Definition at line 239 of file block_memory.h.


Constructor & Destructor Documentation

template<class T, bool __ctor_dtor__ = true>
NLMISC::CBlockMemory< T, __ctor_dtor__ >::CBlockMemory uint    blockSize = 16 [inline]
 

Constructor.

Definition at line 69 of file block_memory.h.

template<class T, bool __ctor_dtor__ = true>
NLMISC::CBlockMemory< T, __ctor_dtor__ >::CBlockMemory const CBlockMemory< T, __ctor_dtor__ > &    other [inline]
 

Definition at line 78 of file block_memory.h.

template<class T, bool __ctor_dtor__ = true>
NLMISC::CBlockMemory< T, __ctor_dtor__ >::~CBlockMemory   [inline]
 

purge().

Definition at line 89 of file block_memory.h.


Member Function Documentation

template<class T, bool __ctor_dtor__ = true>
void NLMISC::CBlockMemory< T, __ctor_dtor__ >::__stl_alloc_changeEltSize uint    eltSize [inline]
 

Definition at line 194 of file block_memory.h.

template<class T, bool __ctor_dtor__ = true>
uint NLMISC::CBlockMemory< T, __ctor_dtor__ >::__stl_alloc_getEltSize   const [inline]
 

Definition at line 210 of file block_memory.h.

template<class T, bool __ctor_dtor__ = true>
T* NLMISC::CBlockMemory< T, __ctor_dtor__ >::allocate   [inline]
 

allocate an element. ctor is called.

Definition at line 96 of file block_memory.h.

template<class T, bool __ctor_dtor__ = true>
void NLMISC::CBlockMemory< T, __ctor_dtor__ >::buildBlock CBlock   block [inline, private]
 

Definition at line 243 of file block_memory.h.

Referenced by NLMISC::CBlockMemory< CNode >::allocate.

template<class T, bool __ctor_dtor__ = true>
void NLMISC::CBlockMemory< T, __ctor_dtor__ >::free T *    ptr [inline]
 

delete an element allocated with this manager. dtor is called. NULL is tested.

Definition at line 141 of file block_memory.h.

template<class T, bool __ctor_dtor__ = true>
void NLMISC::CBlockMemory< T, __ctor_dtor__ >::purge   [inline]
 

delete all blocks, freeing all memory.

It is an error to purge() or delete a CBlockMemory, while elements still remains!! You must free your elements with free(). NB: you can disable this assert if you set NL3D_BlockMemoryAssertOnPurge to false (good to quit a program quickly without uninitialize).

Definition at line 174 of file block_memory.h.

Referenced by NLMISC::CBlockMemory< CNode >::~CBlockMemory.

template<class T, bool __ctor_dtor__ = true>
void NLMISC::CBlockMemory< T, __ctor_dtor__ >::releaseBlock CBlock   block [inline, private]
 

Definition at line 294 of file block_memory.h.

Referenced by NLMISC::CBlockMemory< CNode >::purge.


Member Data Documentation

template<class T, bool __ctor_dtor__ = true>
std::list<CBlock> NLMISC::CBlockMemory::_Blocks [private]
 

list of blocks.

Definition at line 235 of file block_memory.h.

Referenced by NLMISC::CBlockMemory< CNode >::__stl_alloc_changeEltSize, NLMISC::CBlockMemory< CNode >::allocate, and NLMISC::CBlockMemory< CNode >::purge.

template<class T, bool __ctor_dtor__ = true>
uint NLMISC::CBlockMemory::_BlockSize [private]
 

size of a block.

Definition at line 218 of file block_memory.h.

Referenced by NLMISC::CBlockMemory< CNode >::buildBlock, and NLMISC::CBlockMemory< CNode >::CBlockMemory.

template<class T, bool __ctor_dtor__ = true>
uint NLMISC::CBlockMemory::_EltSize [private]
 

size of an element in the block.

Definition at line 220 of file block_memory.h.

Referenced by NLMISC::CBlockMemory< CNode >::__stl_alloc_changeEltSize, NLMISC::CBlockMemory< CNode >::__stl_alloc_getEltSize, NLMISC::CBlockMemory< CNode >::allocate, NLMISC::CBlockMemory< CNode >::buildBlock, NLMISC::CBlockMemory< CNode >::CBlockMemory, and NLMISC::CBlockMemory< CNode >::free.

template<class T, bool __ctor_dtor__ = true>
sint NLMISC::CBlockMemory::_NAllocatedElts [private]
 

number of elements allocated.

Definition at line 222 of file block_memory.h.

Referenced by NLMISC::CBlockMemory< CNode >::allocate, NLMISC::CBlockMemory< CNode >::CBlockMemory, NLMISC::CBlockMemory< CNode >::free, and NLMISC::CBlockMemory< CNode >::purge.

template<class T, bool __ctor_dtor__ = true>
void* NLMISC::CBlockMemory::_NextFreeElt [private]
 

next free element.

Definition at line 224 of file block_memory.h.

Referenced by NLMISC::CBlockMemory< CNode >::allocate, NLMISC::CBlockMemory< CNode >::CBlockMemory, NLMISC::CBlockMemory< CNode >::free, and NLMISC::CBlockMemory< CNode >::purge.


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