Main MRPT website > C++ reference for MRPT 1.9.9
List of all members | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA > Class Template Reference

Detailed Description

template<class DATA_PARAMS, class POOLABLE_DATA>
class mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >

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

Template Parameters
POOLABLE_DATAA struct with user-defined objects which actually contain the memory blocks (e.g. one or more std::vector).
DATA_PARAMSA struct with user information about each memory block (e.g. size of a std::vector)

Definition at line 45 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 &params)
 Request a block of data which fulfils the size requirements stated in params. More...
 
void dump_to_pool (const DATA_PARAMS &params, 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 nullptr 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
 
std::mutex m_pool_cs
 
size_t m_maxPoolEntries
 
bool & m_was_destroyed
 With this trick we get rid of the "global destruction order fiasco" ;-) More...
 

Member Typedef Documentation

◆ TList

template<class DATA_PARAMS, class POOLABLE_DATA>
typedef std::list<std::pair<DATA_PARAMS, POOLABLE_DATA*> > mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::TList
private

Definition at line 48 of file CGenericMemoryPool.h.

Constructor & Destructor Documentation

◆ CGenericMemoryPool()

template<class DATA_PARAMS, class POOLABLE_DATA>
mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::CGenericMemoryPool ( const size_t  max_pool_entries,
bool &  was_destroyed 
)
inlineprivate

◆ ~CGenericMemoryPool()

template<class DATA_PARAMS, class POOLABLE_DATA>
mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::~CGenericMemoryPool ( )
inline

Member Function Documentation

◆ dump_to_pool()

template<class DATA_PARAMS, class POOLABLE_DATA>
void mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::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.

Note
It is a responsibility of the user to allocate in dynamic memory the "POOLABLE_DATA" object with "new".

Definition at line 118 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().

Here is the caller graph for this function:

◆ getInstance()

template<class DATA_PARAMS, class POOLABLE_DATA>
static CGenericMemoryPool<DATA_PARAMS, POOLABLE_DATA>* mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::getInstance ( const size_t  max_pool_entries = 5)
inlinestatic

Construct-on-first-use (~singleton) pattern: Return the unique instance of this class for a given template arguments, or nullptr if it was once created but it's been destroyed (which means we're in the program global destruction phase).

Definition at line 74 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().

Here is the caller graph for this function:

◆ getMemoryPoolMaxSize()

template<class DATA_PARAMS, class POOLABLE_DATA>
size_t mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::getMemoryPoolMaxSize ( ) const
inline

◆ request_memory()

template<class DATA_PARAMS, class POOLABLE_DATA>
POOLABLE_DATA* mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::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().

Returns
The block of data, or nullptr if none suitable was found in the pool.
Note
It is a responsibility of the user to free with "delete" the "POOLABLE_DATA" object itself once the memory has been extracted from its elements.

Definition at line 93 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().

Here is the caller graph for this function:

◆ setMemoryPoolMaxSize()

template<class DATA_PARAMS, class POOLABLE_DATA>
void mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::setMemoryPoolMaxSize ( const size_t  maxNumEntries)
inline

Member Data Documentation

◆ m_maxPoolEntries

template<class DATA_PARAMS, class POOLABLE_DATA>
size_t mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::m_maxPoolEntries
private

◆ m_pool

template<class DATA_PARAMS, class POOLABLE_DATA>
TList mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::m_pool
private

◆ m_pool_cs

template<class DATA_PARAMS, class POOLABLE_DATA>
std::mutex mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::m_pool_cs
private

◆ m_was_destroyed

template<class DATA_PARAMS, class POOLABLE_DATA>
bool& mrpt::system::CGenericMemoryPool< DATA_PARAMS, POOLABLE_DATA >::m_was_destroyed
private



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019