9 #ifndef MRPT_MEMORY_POOL_H 10 #define MRPT_MEMORY_POOL_H 44 template <
class DATA_PARAMS,
class POOLABLE_DATA>
48 typedef std::list<std::pair<DATA_PARAMS, POOLABLE_DATA*>>
TList;
75 const size_t max_pool_entries = 5)
77 static bool was_destroyed =
false;
79 max_pool_entries, was_destroyed);
80 return was_destroyed ? nullptr : &inst;
96 if (
m_pool.empty())
return nullptr;
98 std::lock_guard<std::mutex> lock(
m_pool_cs);
102 if (it->first.isSuitable(
params))
104 POOLABLE_DATA* ret = it->second;
120 std::lock_guard<std::mutex> lock(
m_pool_cs);
124 if (
m_pool.begin()->second)
delete m_pool.begin()->second;
128 m_pool.push_back(
typename TList::value_type(
params, block));
135 std::lock_guard<std::mutex> lock(
m_pool_cs);
void dump_to_pool(const DATA_PARAMS ¶ms, POOLABLE_DATA *block)
Saves the passed data block (characterized by params) to the pool.
POOLABLE_DATA * request_memory(const DATA_PARAMS ¶ms)
Request a block of data which fulfils the size requirements stated in params.
A generic system for versatile memory pooling.
void setMemoryPoolMaxSize(const size_t maxNumEntries)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool & m_was_destroyed
With this trick we get rid of the "global destruction order fiasco" ;-)
std::list< std::pair< DATA_PARAMS, POOLABLE_DATA * > > TList
CGenericMemoryPool(const size_t max_pool_entries, bool &was_destroyed)
size_t getMemoryPoolMaxSize() const
GLenum const GLfloat * params
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...