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
53#include <boost/align/aligned_alloc.hpp>
106#ifdef NEKTAR_USE_THREAD_SAFETY
107 std::scoped_lock l(m_mutex);
109 void *result =
m_pool->malloc();
111#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
124#ifdef NEKTAR_USE_THREAD_SAFETY
125 std::scoped_lock l(m_mutex);
127#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
137 m_pool->free(
const_cast<void *
>(
p));
144#ifdef NEKTAR_USE_THREAD_SAFETY
153 typedef std::map<size_t, std::shared_ptr<detail::ThreadSpecificPool>>
167 typedef PoolMapType::value_type PairType;
168 m_pools.insert(PairType(8, std::shared_ptr<detail::ThreadSpecificPool>(
170 m_pools.insert(PairType(16, std::shared_ptr<detail::ThreadSpecificPool>(
172 m_pools.insert(PairType(32, std::shared_ptr<detail::ThreadSpecificPool>(
174 m_pools.insert(PairType(64, std::shared_ptr<detail::ThreadSpecificPool>(
177 PairType(128, std::shared_ptr<detail::ThreadSpecificPool>(
180 PairType(256, std::shared_ptr<detail::ThreadSpecificPool>(
183 PairType(512, std::shared_ptr<detail::ThreadSpecificPool>(
186 PairType(1024, std::shared_ptr<detail::ThreadSpecificPool>(
213#ifdef NEKTAR_USE_ALIGNED_MEM
214 return boost::alignment::aligned_alloc(
217 return ::operator
new(bytes);
222 PoolMapType::iterator iter =
m_pools.lower_bound(bytes);
224 "The memory manager is mishandling a memory request for " +
225 std::to_string(bytes) +
" bytes of memory.");
227 return (*iter).second->Allocate();
243#ifdef NEKTAR_USE_ALIGNED_MEM
244 boost::alignment::aligned_free(
p);
246 ::operator
delete(
p);
251 PoolMapType::iterator iter =
m_pools.lower_bound(bytes);
253 "The memory manager is mishandling a memory request for " +
254 std::to_string(bytes) +
" bytes of memory.");
256 (*iter).second->Deallocate(
p);
262 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