36 #ifndef NEKTAR_LIB_UTILITES_THREAD_SPECIFIC_POOL_HPP 37 #define NEKTAR_LIB_UTILITES_THREAD_SPECIFIC_POOL_HPP 39 #include <boost/pool/pool.hpp> 45 #ifdef NEKTAR_USE_THREAD_SAFETY 46 #include <boost/thread/mutex.hpp> 102 #ifdef NEKTAR_USE_THREAD_SAFETY 103 boost::mutex::scoped_lock l(m_mutex);
105 void* result =
m_pool->malloc();
107 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG) 109 #endif //defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG) 120 #ifdef NEKTAR_USE_THREAD_SAFETY 121 boost::mutex::scoped_lock l(m_mutex);
123 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG) 131 #endif //defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG) 133 m_pool->free(const_cast<void*>(p));
141 #ifdef NEKTAR_USE_THREAD_SAFETY 142 boost::mutex m_mutex;
150 typedef std::map<size_t, std::shared_ptr<detail::ThreadSpecificPool> >
PoolMapType;
163 typedef PoolMapType::value_type PairType;
192 return m_fourBytePool.Allocate();
194 else if( bytes > m_upperBound )
196 return ::operator
new(bytes);
200 PoolMapType::iterator iter = m_pools.lower_bound(bytes);
201 ASSERTL1(iter != m_pools.end(),
"The memory manager is mishandling a memory request for " +
202 std::to_string(bytes) +
" bytes of memory.");
204 return (*iter).second->Allocate();
216 m_fourBytePool.Deallocate(p);
218 else if( bytes > m_upperBound )
220 ::operator
delete(
p);
224 PoolMapType::iterator iter = m_pools.lower_bound(bytes);
225 ASSERTL1(iter != m_pools.end(),
"The memory manager is mishandling a memory request for " +
226 std::to_string(bytes) +
" bytes of memory.");
228 (*iter).second->Deallocate(p);
234 std::map<size_t, std::shared_ptr<detail::ThreadSpecificPool> >
m_pools;
243 #endif //NEKATAR_LIB_UTILITES_THREAD_SPECIFIC_POOL_HPP detail::ThreadSpecificPool m_fourBytePool
void Deallocate(void *p, size_t bytes)
Deallocate memory claimed by an earlier call to allocate.
std::map< size_t, std::shared_ptr< detail::ThreadSpecificPool > > PoolMapType
void * Allocate(size_t bytes)
Allocate a block of memory of size ByteSize.
#define LIB_UTILITIES_EXPORT
MemPool & GetMemoryPool()
std::map< size_t, std::shared_ptr< detail::ThreadSpecificPool > > m_pools
void Deallocate(const void *p)
Deallocate memory claimed by an earlier call to allocate.
ThreadSpecificPool(size_t ByteSize)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
void * Allocate()
Allocate a block of memory of size ByteSize.