Nektar++
Public Member Functions | Private Attributes | List of all members
Nektar::detail::ThreadSpecificPool Class Reference

#include <ThreadSpecificPool.hpp>

Public Member Functions

 ThreadSpecificPool (size_t ByteSize)
 
 ~ThreadSpecificPool ()
 
voidAllocate ()
 Allocate a block of memory of size ByteSize. More...
 
void Deallocate (const void *p)
 Deallocate memory claimed by an earlier call to allocate. More...
 

Private Attributes

boost::pool * m_pool
 
size_t m_blockSize
 

Detailed Description

Definition at line 85 of file ThreadSpecificPool.hpp.

Constructor & Destructor Documentation

◆ ThreadSpecificPool()

Nektar::detail::ThreadSpecificPool::ThreadSpecificPool ( size_t  ByteSize)
inline

Definition at line 88 of file ThreadSpecificPool.hpp.

88  :
89  m_pool(),
90  m_blockSize(ByteSize)
91  {
92  // We can't do the new in the constructor list because the
93  // thread specific pointer doesn't have a supporting
94  // constructor.
95  m_pool = new boost::pool<>(m_blockSize);
96  }

References m_blockSize, and m_pool.

◆ ~ThreadSpecificPool()

Nektar::detail::ThreadSpecificPool::~ThreadSpecificPool ( )
inline

Definition at line 98 of file ThreadSpecificPool.hpp.

99  {
100  // Need to call delete manually, otherwise memory is leaking.
101  delete m_pool;
102 
103  }

References m_pool.

Member Function Documentation

◆ Allocate()

void* Nektar::detail::ThreadSpecificPool::Allocate ( )
inline

Allocate a block of memory of size ByteSize.

Exceptions
std::bad_allocif memory is exhausted.

Definition at line 107 of file ThreadSpecificPool.hpp.

108  {
109 #ifdef NEKTAR_USE_THREAD_SAFETY
110  boost::mutex::scoped_lock l(m_mutex);
111 #endif
112  void* result = m_pool->malloc();
113 
114 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
115  memset(result, 0, m_blockSize);
116 #endif //defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
117 
118  return result;
119  }

References m_blockSize, and m_pool.

Referenced by Nektar::MemPool::Allocate().

◆ Deallocate()

void Nektar::detail::ThreadSpecificPool::Deallocate ( const void p)
inline

Deallocate memory claimed by an earlier call to allocate.

Attention
It is an error to deallocate memory not allocated from this pool. Doing this will result in undefined behavior.

Definition at line 125 of file ThreadSpecificPool.hpp.

126  {
127 #ifdef NEKTAR_USE_THREAD_SAFETY
128  boost::mutex::scoped_lock l(m_mutex);
129 #endif
130 #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
131  // The idea here is to fill the returned memory with some known
132  // pattern, then detect that pattern on the allocate. If the
133  // pattern is no longer there then some memory corruption has
134  // occurred. However, I'm not sure how to distinguish between first
135  // time allocations and repeat allocations.
136 
137  //memset(p, '+', m_pool->get_requested_size());
138 #endif //defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
139 
140  m_pool->free(const_cast<void*>(p));
141  }

References m_pool, and CellMLToNektar.cellml_metadata::p.

Referenced by Nektar::MemPool::Deallocate().

Member Data Documentation

◆ m_blockSize

size_t Nektar::detail::ThreadSpecificPool::m_blockSize
private

Definition at line 147 of file ThreadSpecificPool.hpp.

Referenced by Allocate(), and ThreadSpecificPool().

◆ m_pool

boost::pool* Nektar::detail::ThreadSpecificPool::m_pool
private