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::obs::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) |
Definition at line 38 of file CGenericMemoryPool.h.
#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. More... | |
void | dump_to_pool (const DATA_PARAMS ¶ms, POOLABLE_DATA *block) |
Saves the passed data block (characterized by params) to the pool. More... | |
~CGenericMemoryPool () | |
Static Public Member Functions | |
static CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA > * | getInstance (const size_t max_pool_entries=5) |
Construct-on-first-use (~singleton) pattern: Return the unique instance of this class for a given template arguments, or NULL if it was once created but it's been destroyed (which means we're in the program global destruction phase). More... | |
Private Types | |
typedef std::list< std::pair< DATA_PARAMS, POOLABLE_DATA * > > | TList |
Private Member Functions | |
CGenericMemoryPool (const size_t max_pool_entries, bool &was_destroyed) | |
Private Attributes | |
TList | m_pool |
mrpt::synch::CCriticalSection | m_pool_cs |
size_t | m_maxPoolEntries |
bool & | m_was_destroyed |
With this trick we get rid of the "global destruction order fiasco" ;-) More... | |
|
private |
Definition at line 41 of file CGenericMemoryPool.h.
|
inlineprivate |
Definition at line 47 of file CGenericMemoryPool.h.
References mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::m_was_destroyed.
|
inline |
|
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 92 of file CGenericMemoryPool.h.
References mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::m_maxPoolEntries, mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::m_pool, and mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::m_pool_cs.
Referenced by mrpt::opengl::CTexturedObject::loadTextureInOpenGL(), mempool_donate_range_matrix(), and mempool_donate_xyz_buffers().
|
inlinestatic |
Construct-on-first-use (~singleton) pattern: Return the unique instance of this class for a given template arguments, or NULL if it was once created but it's been destroyed (which means we're in the program global destruction phase).
Definition at line 59 of file CGenericMemoryPool.h.
Referenced by mrpt::opengl::CTexturedObject::loadTextureInOpenGL(), mempool_donate_range_matrix(), mempool_donate_xyz_buffers(), mrpt::obs::CObservationRGBD360::rangeImage_setSize(), mrpt::obs::CObservation3DRangeScan::rangeImage_setSize(), reserveDataBuffer(), and mrpt::obs::CObservation3DRangeScan::resizePoints3DVectors().
|
inline |
Definition at line 53 of file CGenericMemoryPool.h.
References mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::m_maxPoolEntries.
|
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 71 of file CGenericMemoryPool.h.
References mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::m_pool, and mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::m_pool_cs.
Referenced by mrpt::obs::CObservationRGBD360::rangeImage_setSize(), mrpt::obs::CObservation3DRangeScan::rangeImage_setSize(), reserveDataBuffer(), and mrpt::obs::CObservation3DRangeScan::resizePoints3DVectors().
|
inline |
Definition at line 54 of file CGenericMemoryPool.h.
References mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::m_maxPoolEntries.
|
private |
Definition at line 44 of file CGenericMemoryPool.h.
Referenced by mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::dump_to_pool(), mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::getMemoryPoolMaxSize(), and mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::setMemoryPoolMaxSize().
|
private |
Definition at line 42 of file CGenericMemoryPool.h.
Referenced by mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::dump_to_pool(), mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::request_memory(), and mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::~CGenericMemoryPool().
|
private |
Definition at line 43 of file CGenericMemoryPool.h.
Referenced by mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::dump_to_pool(), mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::request_memory(), and mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::~CGenericMemoryPool().
|
private |
With this trick we get rid of the "global destruction order fiasco" ;-)
Definition at line 45 of file CGenericMemoryPool.h.
Referenced by mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::CGenericMemoryPool(), and mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::~CGenericMemoryPool().
Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019 |