35 #ifndef _BLAZE_UTIL_MEMORYPOOL_H_
36 #define _BLAZE_UTIL_MEMORYPOOL_H_
67 template<
typename Type,
size_t Blocksize >
128 inline void free(
void* rawMemory );
166 template<
typename Type,
size_t Blocksize >
170 for(
size_t i=0; i<Blocksize-1; ++i ) {
183 template<
typename Type,
size_t Blocksize >
186 delete [] rawMemory_;
202 template<
typename Type,
size_t Blocksize >
216 template<
typename Type,
size_t Blocksize >
219 for(
typename Blocks::iterator it=
blocks_.begin(); it!=
blocks_.end(); ++it )
230 template<
typename Type,
size_t Blocksize >
253 template<
typename Type,
size_t Blocksize >
270 template<
typename Type,
size_t Blocksize >
273 for(
typename Blocks::const_iterator it=
blocks_.begin(); it!=
blocks_.end(); ++it )
276 if( toRelease >= it->rawMemory_ && toRelease < it->rawMemory_+Blocksize )
279 const byte_t*
const ptr1( reinterpret_cast<const byte_t*>(toRelease) );
280 const byte_t*
const ptr2( reinterpret_cast<const byte_t*>(it->rawMemory_) );
282 if( ( ptr1 - ptr2 ) %
sizeof(
FreeObject) != 0 )
return false;
287 if( ptr == toRelease )
return false;
FreeObject * freeList_
Head of the free list.
Definition: MemoryPool.h:143
Header file for basic type definitions.
unsigned char byte_t
Byte data type of the Blaze library.The byte data type is guaranteed to be an integral data type of s...
Definition: Types.h:79
FreeObject * rawMemory_
Allocated memory pool of the block.
Definition: MemoryPool.h:99
Base class for non-copyable class instances.
Blocks blocks_
Vector of available memory blocks.
Definition: MemoryPool.h:144
Memory pool for small objects.The memory pool efficiently improves the performance of dynamic memory ...
Definition: MemoryPool.h:68
byte_t dummy_[sizeof(Type)]
Dummy array to create an object of the appropriate size.
Definition: MemoryPool.h:76
void init()
Initialization of a memory block.
Definition: MemoryPool.h:167
void free()
Release of the entire memory block.
Definition: MemoryPool.h:184
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
Base class for non-copyable class instances.The NonCopyable class is intended to work as a base class...
Definition: NonCopyable.h:63
A single element of the free list of the memory pool.
Definition: MemoryPool.h:74
bool checkMemory(FreeObject *rawMemory) const
Performing a number of checks on the memory to be released.
Definition: MemoryPool.h:271
Header file for run time assertion macros.
std::vector< Block > Blocks
Vector of memory blocks.
Definition: MemoryPool.h:106
void free(void *rawMemory)
Deallocation of raw memory for an object of type Type.
Definition: MemoryPool.h:254
Memory block within the memory bool.
Definition: MemoryPool.h:85
void * malloc()
Allocation of raw memory for an object of type Type.
Definition: MemoryPool.h:231
~MemoryPool()
Destructor of the memory pool.
Definition: MemoryPool.h:217
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
MemoryPool()
Constructor of the memory pool.
Definition: MemoryPool.h:203
FreeObject * next_
Pointer to the next free object.
Definition: MemoryPool.h:75