NLMISC::CPoolMemory< T > Class Template Reference

#include <pool_memory.h>


Detailed Description

template<class T>
class NLMISC::CPoolMemory< T >

Pool memory allocation

This memory manager allocates bloc of elements and free all the elements at the same time. Useful for temporary allocation.

Author:
Cyril 'Hulud' Corvazier

Nevrax France

Date:
2001

Definition at line 49 of file pool_memory.h.

Public Member Functions

T * allocate ()
 CPoolMemory (uint blockSize=10)
void free ()
void purge ()

Private Attributes

std::list< std::vector< T > > _BlockList
std::list< std::vector< T
> >::iterator 
_BlockPointer
uint _BlockSize


Constructor & Destructor Documentation

template<class T>
NLMISC::CPoolMemory< T >::CPoolMemory uint  blockSize = 10  )  [inline]
 

Definition at line 57 of file pool_memory.h.

00058         {
00059                 _BlockSize=blockSize;
00060                 _BlockPointer=_BlockList.end();
00061         }


Member Function Documentation

template<class T>
T* NLMISC::CPoolMemory< T >::allocate  )  [inline]
 

Definition at line 68 of file pool_memory.h.

00069         {
00070                 // End of block ?
00071                 if ( (_BlockPointer!=_BlockList.end()) && (_BlockPointer->size()>=_BlockSize) )
00072                 {
00073                         // Get next block
00074                         _BlockPointer++;
00075                 }
00076 
00077                 // Out of memory ?
00078                 if (_BlockPointer==_BlockList.end())
00079                 {
00080                         // Add a block
00081                         _BlockList.resize (_BlockList.size()+1);
00082 
00083                         // Pointer on the new block
00084                         _BlockPointer=_BlockList.end ();
00085                         _BlockPointer--;
00086 
00087                         // Reserve it
00088                         _BlockPointer->reserve (_BlockSize);
00089                 }
00090 
00091                 // Allocate
00092                 _BlockPointer->resize (_BlockPointer->size()+1);
00093 
00094                 // Return the pointer
00095                 return &*((_BlockPointer->end ()-1));
00096         }

template<class T>
void NLMISC::CPoolMemory< T >::free  )  [inline]
 

Definition at line 101 of file pool_memory.h.

00102         {
00103                 typename std::list< std::vector<T> >::iterator ite=_BlockList.begin();
00104                 while (ite!=_BlockList.end())
00105                 {
00106                         // Clear the block
00107                         ite->clear ();
00108 
00109                         // Check size in not zero
00110                         nlassert (ite->capacity ()>0);
00111 
00112                         ite++;
00113                 }
00114                 // Pointer at the begining
00115                 _BlockPointer=_BlockList.begin();
00116         }

template<class T>
void NLMISC::CPoolMemory< T >::purge  )  [inline]
 

Definition at line 121 of file pool_memory.h.

00122         {
00123                 _BlockList.clear();
00124                 _BlockPointer=_BlockList.end();
00125         }


Field Documentation

template<class T>
std::list< std::vector<T> > NLMISC::CPoolMemory< T >::_BlockList [private]
 

Definition at line 129 of file pool_memory.h.

template<class T>
std::list< std::vector<T> >::iterator NLMISC::CPoolMemory< T >::_BlockPointer [private]
 

Definition at line 130 of file pool_memory.h.

template<class T>
uint NLMISC::CPoolMemory< T >::_BlockSize [private]
 

Definition at line 128 of file pool_memory.h.


The documentation for this class was generated from the following file:
Generated on Tue Mar 16 13:28:21 2004 for NeL by doxygen 1.3.6