Blaze 3.9
Classes | Private Types | List of all members
blaze::MemoryPool< Type, Blocksize > Class Template Reference

Memory pool for small objects. More...

#include <MemoryPool.h>

Inherits blaze::NonCopyable.

Classes

struct  Block
 Memory block within the memory bool. More...
 
union  FreeObject
 A single element of the free list of the memory pool. More...
 

Public Member Functions

Constructor
 MemoryPool ()
 Constructor of the memory pool.
 
Destructor
 ~MemoryPool ()
 Destructor of the memory pool.
 

Private Types

using Blocks = std::vector< Block >
 Vector of memory blocks.
 

Private Attributes

Member variables
FreeObjectfreeList_
 Head of the free list.
 
Blocks blocks_
 Vector of available memory blocks.
 

Memory management functions

void * malloc ()
 Allocation of raw memory for an object of type Type. More...
 
void free (void *rawMemory)
 Deallocation of raw memory for an object of type Type. More...
 
bool checkMemory (FreeObject *rawMemory) const
 Performing a number of checks on the memory to be released. More...
 

Detailed Description

template<typename Type, size_t Blocksize>
class blaze::MemoryPool< Type, Blocksize >

Memory pool for small objects.

The memory pool efficiently improves the performance of dynamic memory allocations for small objects. By allocating a large block of memory that can be dynamically assigned to small objects, the memory allocation is reduced from a few hundred cycles to only a few cycles.
The memory pool is build from memory blocks of type Block, which hold the memory for a specified number of objects. The memory of these blocks is managed as a single free list.

Member Function Documentation

◆ checkMemory()

template<typename Type , size_t Blocksize>
bool blaze::MemoryPool< Type, Blocksize >::checkMemory ( FreeObject toRelease) const
inlineprivate

Performing a number of checks on the memory to be released.

Parameters
toReleasePointer to the memory to be released.
Returns
true if the memory check succeeds, false if an error is encountered.

◆ free()

template<typename Type , size_t Blocksize>
void blaze::MemoryPool< Type, Blocksize >::free ( void *  rawMemory)
inline

Deallocation of raw memory for an object of type Type.

Parameters
rawMemoryPointer to the raw memory.
Returns
void

◆ malloc()

template<typename Type , size_t Blocksize>
void * blaze::MemoryPool< Type, Blocksize >::malloc
inline

Allocation of raw memory for an object of type Type.

Returns
Pointer to the raw memory.

The documentation for this class was generated from the following file: