A generic system for versatile memory pooling.
This class implements the singleton pattern so a unique instance exists for each combination of template parameters. All methods are thread-safe.
Basic usage:
Notice that memory requests are checked against memory blocks in the pool via a user-defined function:
bool POOLABLE_DATA::isSuitable(const POOLABLE_DATA & req) const { ... }
For an example of how to handle a memory pool, see the class mrpt::slam::CObservation3DRangeScan
| POOLABLE_DATA | A struct with user-defined objects which actually contain the memory blocks (e.g. one or more std::vector). |
| DATA_PARAMS | A struct with user information about each memory block (e.g. size of a std::vector) |
#include <mrpt/system/CGenericMemoryPool.h>
Public Member Functions | |
| size_t | getMemoryPoolMaxSize () const |
| void | setMemoryPoolMaxSize (const size_t maxNumEntries) |
| POOLABLE_DATA * | request_memory (const DATA_PARAMS ¶ms) |
| Request a block of data which fulfils the size requirements stated in params. | |
| void | dump_to_pool (const DATA_PARAMS ¶ms, POOLABLE_DATA *block) |
| Saves the passed data block (characterized by params) to the pool. | |
| ~CGenericMemoryPool () | |
Static Public Member Functions | |
| static CGenericMemoryPool < DATA_PARAMS, POOLABLE_DATA > & | getInstance () |
| Singleton: Return the unique instance of this class for a given template arguments: | |
Private Types | |
| typedef std::list< std::pair < DATA_PARAMS, POOLABLE_DATA * > > | TList |
Private Member Functions | |
| CGenericMemoryPool () | |
Private Attributes | |
| TList | m_pool |
| mrpt::synch::CCriticalSection | m_pool_cs |
| size_t | m_maxPoolEntries |
typedef std::list<std::pair<DATA_PARAMS,POOLABLE_DATA*> > mrpt::system::CGenericMemoryPool::TList [private] |
Definition at line 59 of file CGenericMemoryPool.h.
| mrpt::system::CGenericMemoryPool::CGenericMemoryPool | ( | ) | [inline, private] |
Definition at line 64 of file CGenericMemoryPool.h.
| mrpt::system::CGenericMemoryPool::~CGenericMemoryPool | ( | ) | [inline] |
Definition at line 115 of file CGenericMemoryPool.h.
| void mrpt::system::CGenericMemoryPool::dump_to_pool | ( | const DATA_PARAMS & | params, |
| POOLABLE_DATA * | block | ||
| ) | [inline] |
Saves the passed data block (characterized by params) to the pool.
If the overall size of the pool is above the limit, the oldest entry is removed.
Definition at line 105 of file CGenericMemoryPool.h.
References m_pool_cs, m_pool, and m_maxPoolEntries.
| static CGenericMemoryPool<DATA_PARAMS,POOLABLE_DATA>& mrpt::system::CGenericMemoryPool::getInstance | ( | ) | [inline, static] |
Singleton: Return the unique instance of this class for a given template arguments:
Definition at line 73 of file CGenericMemoryPool.h.
| size_t mrpt::system::CGenericMemoryPool::getMemoryPoolMaxSize | ( | ) | const [inline] |
Definition at line 69 of file CGenericMemoryPool.h.
References m_maxPoolEntries.
| POOLABLE_DATA* mrpt::system::CGenericMemoryPool::request_memory | ( | const DATA_PARAMS & | params | ) | [inline] |
Request a block of data which fulfils the size requirements stated in params.
Notice that the decision on the suitability of each pool'ed block is done by DATA_PARAMS::isSuitable().
Definition at line 84 of file CGenericMemoryPool.h.
| void mrpt::system::CGenericMemoryPool::setMemoryPoolMaxSize | ( | const size_t | maxNumEntries | ) | [inline] |
Definition at line 70 of file CGenericMemoryPool.h.
References m_maxPoolEntries.
size_t mrpt::system::CGenericMemoryPool::m_maxPoolEntries [private] |
Definition at line 62 of file CGenericMemoryPool.h.
Referenced by getMemoryPoolMaxSize(), setMemoryPoolMaxSize(), and dump_to_pool().
Definition at line 60 of file CGenericMemoryPool.h.
Referenced by request_memory(), dump_to_pool(), and ~CGenericMemoryPool().
Definition at line 61 of file CGenericMemoryPool.h.
Referenced by request_memory(), dump_to_pool(), and ~CGenericMemoryPool().
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |