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