template <typename VectorType>
-typename GrowingVectorMemory<VectorType>::Pool
- GrowingVectorMemory<VectorType>::pool;
+typename GrowingVectorMemory<VectorType>::Pool &
+GrowingVectorMemory<VectorType>::get_pool()
+{
+ static GrowingVectorMemory<VectorType>::Pool pool;
+ return pool;
+}
+
+
template <typename VectorType>
Threads::Mutex GrowingVectorMemory<VectorType>::mutex;
+
+
template <typename VectorType>
inline GrowingVectorMemory<VectorType>::Pool::Pool()
: data(nullptr)
, log_statistics(log_statistics)
{
std::lock_guard<std::mutex> lock(mutex);
- pool.initialize(initial_size);
+ get_pool().initialize(initial_size);
}
deallog << "GrowingVectorMemory:Overall allocated vectors: "
<< total_alloc << std::endl;
deallog << "GrowingVectorMemory:Maximum allocated vectors: "
- << pool.data->size() << std::endl;
+ << get_pool().data->size() << std::endl;
}
}
++current_alloc;
// see if there is a free vector
// available in our list
- for (typename std::vector<entry_type>::iterator i = pool.data->begin();
- i != pool.data->end();
+ for (typename std::vector<entry_type>::iterator i = get_pool().data->begin();
+ i != get_pool().data->end();
++i)
{
if (i->first == false)
}
// no free vector found, so let's just allocate a new one
- pool.data->emplace_back(
+ get_pool().data->emplace_back(
entry_type(true, std_cxx14::make_unique<VectorType>()));
- return pool.data->back().second.get();
+ return get_pool().data->back().second.get();
}
{
std::lock_guard<std::mutex> lock(mutex);
- for (typename std::vector<entry_type>::iterator i = pool.data->begin();
- i != pool.data->end();
+ for (typename std::vector<entry_type>::iterator i = get_pool().data->begin();
+ i != get_pool().data->end();
++i)
{
if (v == i->second.get())
{
std::lock_guard<std::mutex> lock(mutex);
- if (pool.data != nullptr)
- pool.data->clear();
+ if (get_pool().data != nullptr)
+ get_pool().data->clear();
}
std::lock_guard<std::mutex> lock(mutex);
std::size_t result = sizeof(*this);
- const typename std::vector<entry_type>::const_iterator end = pool.data->end();
- for (typename std::vector<entry_type>::const_iterator i = pool.data->begin();
+ const typename std::vector<entry_type>::const_iterator end =
+ get_pool().data->end();
+ for (typename std::vector<entry_type>::const_iterator i =
+ get_pool().data->begin();
i != end;
++i)
result += sizeof(*i) + MemoryConsumption::memory_consumption(i->second);