42 template <
class DATA_PARAMS,
class POOLABLE_DATA>
46 using TList = std::list<std::pair<DATA_PARAMS, POOLABLE_DATA*>>;
73 const size_t max_pool_entries = 5)
75 static bool was_destroyed =
false;
77 max_pool_entries, was_destroyed);
78 return was_destroyed ? nullptr : &inst;
94 if (
m_pool.empty())
return nullptr;
96 std::lock_guard<std::mutex> lock(
m_pool_cs);
99 if (it->first.isSuitable(
params))
101 POOLABLE_DATA* ret = it->second;
117 std::lock_guard<std::mutex> lock(
m_pool_cs);
121 if (
m_pool.begin()->second)
delete m_pool.begin()->second;
125 m_pool.push_back(
typename TList::value_type(
params, block));
132 std::lock_guard<std::mutex> lock(
m_pool_cs);
133 for (
auto it =
m_pool.begin(); it !=
m_pool.end(); ++it)
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.
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)
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
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...