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
47 #include <boost/thread/mutex.hpp>
50 #ifdef NEKTAR_USE_ALIGNED_MEM
51 #include <boost/align/aligned_alloc.hpp>
109 #ifdef NEKTAR_USE_THREAD_SAFETY
110 boost::mutex::scoped_lock l(m_mutex);
112 void* result =
m_pool->malloc();
114 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
127 #ifdef NEKTAR_USE_THREAD_SAFETY
128 boost::mutex::scoped_lock l(m_mutex);
130 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
140 m_pool->free(
const_cast<void*
>(
p));
148 #ifdef NEKTAR_USE_THREAD_SAFETY
149 boost::mutex m_mutex;
157 typedef std::map<size_t, std::shared_ptr<detail::ThreadSpecificPool> >
PoolMapType;
170 typedef PoolMapType::value_type PairType;
203 #ifdef NEKTAR_USE_ALIGNED_MEM
206 return ::operator
new(bytes);
211 PoolMapType::iterator iter =
m_pools.lower_bound(bytes);
212 ASSERTL1(iter !=
m_pools.end(),
"The memory manager is mishandling a memory request for " +
213 std::to_string(bytes) +
" bytes of memory.");
215 return (*iter).second->Allocate();
231 #ifdef NEKTAR_USE_ALIGNED_MEM
232 boost::alignment::aligned_free(
p);
234 ::operator
delete(
p);
239 PoolMapType::iterator iter =
m_pools.lower_bound(bytes);
240 ASSERTL1(iter !=
m_pools.end(),
"The memory manager is mishandling a memory request for " +
241 std::to_string(bytes) +
" bytes of memory.");
243 (*iter).second->Deallocate(
p);
249 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.
The above copyright notice and this permission notice shall be included.
MemPool & GetMemoryPool()
typename abi< ScalarType >::type simd