Go to the documentation of this file.
44 template <
class DATA_PARAMS,
class POOLABLE_DATA>
48 using TList = std::list<std::pair<DATA_PARAMS, POOLABLE_DATA*>>;
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);
POOLABLE_DATA * request_memory(const DATA_PARAMS ¶ms)
Request a block of data which fulfils the size requirements stated in params.
std::list< std::pair< DATA_PARAMS, POOLABLE_DATA * > > TList
void dump_to_pool(const DATA_PARAMS ¶ms, POOLABLE_DATA *block)
Saves the passed data block (characterized by params) to the pool.
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.
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)
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...
size_t getMemoryPoolMaxSize() const
GLenum const GLfloat * params
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |