Go to the documentation of this file.
9 #ifndef MRPT_MEMORY_POOL_H
10 #define MRPT_MEMORY_POOL_H
37 template <
class DATA_PARAMS,
class POOLABLE_DATA>
41 typedef std::list<std::pair<DATA_PARAMS,POOLABLE_DATA*> >
TList;
61 static bool was_destroyed =
false;
63 return was_destroyed ? NULL : &inst;
74 if (
m_pool.empty())
return NULL;
78 if (it->first.isSuitable(params))
80 POOLABLE_DATA * ret = it->second;
98 if (
m_pool.begin()->second)
delete m_pool.begin()->second;
102 m_pool.push_back(
typename TList::value_type(params,block) );
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.
A class acquiring a CCriticalSection at its constructor, and releasing it at destructor.
void setMemoryPoolMaxSize(const size_t maxNumEntries)
A generic system for versatile memory pooling.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::synch::CCriticalSection m_pool_cs
This class provides simple critical sections functionality.
std::list< std::pair< DATA_PARAMS, POOLABLE_DATA * > > TList
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 tem...
bool & m_was_destroyed
With this trick we get rid of the "global destruction order fiasco" ;-)
CGenericMemoryPool(const size_t max_pool_entries, bool &was_destroyed)
size_t getMemoryPoolMaxSize() const
Page generated by Doxygen 1.8.16 for MRPT 1.4.0 SVN: at Mon Oct 14 22:32:58 UTC 2019 | | |