Main MRPT website > C++ reference
MRPT logo
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
mrpt::system::CGenericMemoryPool Class Reference

Detailed Description

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

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)

#include <mrpt/system/CGenericMemoryPool.h>

List of all members.

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.
void dump_to_pool (const DATA_PARAMS &params, 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

Member Typedef Documentation

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

Definition at line 59 of file CGenericMemoryPool.h.


Constructor & Destructor Documentation

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.

References m_pool_cs, and m_pool.


Member Function Documentation

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.

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

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().

Returns:
The block of data, or NULL 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 84 of file CGenericMemoryPool.h.

References m_pool, and m_pool_cs.

void mrpt::system::CGenericMemoryPool::setMemoryPoolMaxSize ( const size_t  maxNumEntries) [inline]

Definition at line 70 of file CGenericMemoryPool.h.

References m_maxPoolEntries.


Member Data Documentation

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