35 #ifndef _BLAZE_UTIL_MEMORYPOOL_H_
36 #define _BLAZE_UTIL_MEMORYPOOL_H_
68 template<
typename Type,
size_t Blocksize >
129 inline void free(
void* rawMemory );
167 template<
typename Type,
size_t Blocksize >
171 for(
size_t i=0; i<Blocksize-1; ++i ) {
184 template<
typename Type,
size_t Blocksize >
187 delete [] rawMemory_;
203 template<
typename Type,
size_t Blocksize >
217 template<
typename Type,
size_t Blocksize >
220 for(
typename Blocks::iterator it=
blocks_.begin(); it!=
blocks_.end(); ++it )
231 template<
typename Type,
size_t Blocksize >
254 template<
typename Type,
size_t Blocksize >
271 template<
typename Type,
size_t Blocksize >
274 for(
typename Blocks::const_iterator it=
blocks_.begin(); it!=
blocks_.end(); ++it )
277 if( toRelease >= it->rawMemory_ && toRelease < it->rawMemory_+Blocksize )
280 const byte*
const ptr1( reinterpret_cast<const byte*>(toRelease) );
281 const byte*
const ptr2( reinterpret_cast<const byte*>(it->rawMemory_) );
283 if( ( ptr1 - ptr2 ) %
sizeof(
FreeObject) != 0 )
return false;
288 if( ptr == toRelease )
return false;
FreeObject * freeList_
Head of the free list.
Definition: MemoryPool.h:144
FreeObject * rawMemory_
Allocated memory pool of the block.
Definition: MemoryPool.h:100
Base class for non-copyable class instances.
Blocks blocks_
Vector of available memory blocks.
Definition: MemoryPool.h:145
Memory pool for small objects.The memory pool efficiently improves the performance of dynamic memory ...
Definition: MemoryPool.h:69
void init()
Initialization of a memory block.
Definition: MemoryPool.h:168
void free()
Release of the entire memory block.
Definition: MemoryPool.h:185
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:75
Header file for the byte type.
bool checkMemory(FreeObject *rawMemory) const
Performing a number of checks on the memory to be released.
Definition: MemoryPool.h:272
Header file for run time assertion macros.
std::vector< Block > Blocks
Vector of memory blocks.
Definition: MemoryPool.h:107
void free(void *rawMemory)
Deallocation of raw memory for an object of type Type.
Definition: MemoryPool.h:255
Memory block within the memory bool.
Definition: MemoryPool.h:86
void * malloc()
Allocation of raw memory for an object of type Type.
Definition: MemoryPool.h:232
~MemoryPool()
Destructor of the memory pool.
Definition: MemoryPool.h:218
unsigned char byte
Byte data type of the Blaze library.The byte data type is guaranteed to be an integral data type of s...
Definition: Byte.h:61
Header file for basic type definitions.
byte dummy_[sizeof(Type)]
Dummy array to create an object of the appropriate size.
Definition: MemoryPool.h:77
#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:204
FreeObject * next_
Pointer to the next free object.
Definition: MemoryPool.h:76