36#ifndef NEKTAR_LIB_UTILITES_THREAD_SPECIFIC_POOL_HPP
37#define NEKTAR_LIB_UTILITES_THREAD_SPECIFIC_POOL_HPP
39#include <boost/pool/pool.hpp>
46#ifdef NEKTAR_USE_THREAD_SAFETY
50#ifdef NEKTAR_USE_ALIGNED_MEM
105#ifdef NEKTAR_USE_THREAD_SAFETY
106 std::scoped_lock l(m_mutex);
108 void *result =
m_pool->malloc();
110#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
123#ifdef NEKTAR_USE_THREAD_SAFETY
124 std::scoped_lock l(m_mutex);
126#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
136 m_pool->free(
const_cast<void *
>(p));
143#ifdef NEKTAR_USE_THREAD_SAFETY
152 typedef std::map<size_t, std::shared_ptr<detail::ThreadSpecificPool>>
166 typedef PoolMapType::value_type PairType;
167 m_pools.insert(PairType(8, std::shared_ptr<detail::ThreadSpecificPool>(
169 m_pools.insert(PairType(16, std::shared_ptr<detail::ThreadSpecificPool>(
171 m_pools.insert(PairType(32, std::shared_ptr<detail::ThreadSpecificPool>(
173 m_pools.insert(PairType(64, std::shared_ptr<detail::ThreadSpecificPool>(
176 PairType(128, std::shared_ptr<detail::ThreadSpecificPool>(
179 PairType(256, std::shared_ptr<detail::ThreadSpecificPool>(
182 PairType(512, std::shared_ptr<detail::ThreadSpecificPool>(
185 PairType(1024, std::shared_ptr<detail::ThreadSpecificPool>(
212#ifdef NEKTAR_USE_ALIGNED_MEM
215 return ::operator
new(bytes);
220 PoolMapType::iterator iter =
m_pools.lower_bound(bytes);
222 "The memory manager is mishandling a memory request for " +
223 std::to_string(bytes) +
" bytes of memory.");
225 return (*iter).second->Allocate();
241#ifdef NEKTAR_USE_ALIGNED_MEM
244 ::operator
delete(p);
249 PoolMapType::iterator iter =
m_pools.lower_bound(bytes);
251 "The memory manager is mishandling a memory request for " +
252 std::to_string(bytes) +
" bytes of memory.");
254 (*iter).second->Deallocate(p);
260 std::map<size_t, std::shared_ptr<detail::ThreadSpecificPool>>
m_pools;
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
#define LIB_UTILITIES_EXPORT
void Deallocate(void *p, size_t bytes)
Deallocate memory claimed by an earlier call to allocate.
detail::ThreadSpecificPool m_fourBytePool
std::map< size_t, std::shared_ptr< detail::ThreadSpecificPool > > m_pools
std::map< size_t, std::shared_ptr< detail::ThreadSpecificPool > > PoolMapType
void * Allocate(size_t bytes)
Allocate a block of memory of size ByteSize.
ThreadSpecificPool(size_t ByteSize)
void Deallocate(const void *p)
Deallocate memory claimed by an earlier call to allocate.
void * Allocate()
Allocate a block of memory of size ByteSize.
MemPool & GetMemoryPool()
typename abi< ScalarType, width >::type simd