Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::MemoryPool Class Reference

Core class that represents a memory pool. More...

Public Member Functions

 MemoryPool (unsigned int blockSize, unsigned int size=1024, bool canGrow=true)
 Constructs a MemoryPool object. More...
 
 MemoryPool (const MemoryPool &)=delete
 
 MemoryPool (MemoryPool &&pool) noexcept
 Constructs a MemoryPool object by move semantic. More...
 
void * Allocate (unsigned int size)
 Allocates enough memory for the size and returns a pointer to it. More...
 
template<typename T >
void Delete (T *ptr)
 Deletes the memory represented by the poiner. More...
 
void Free (void *ptr)
 Frees the memory represented by the poiner. More...
 
unsigned int GetBlockSize () const
 Gets the block size. More...
 
unsigned int GetFreeBlocks () const
 Gets the number of free blocks. More...
 
unsigned int GetSize () const
 Gets the pool size. More...
 
template<typename T , typename... Args>
T * New (Args &&... args)
 Creates a new value of type T with arguments. More...
 
MemoryPooloperator= (const MemoryPool &)=delete
 
MemoryPooloperator= (MemoryPool &&pool) noexcept
 Assigns the content of another pool by move semantic. More...
 

Detailed Description

Core class that represents a memory pool.

Constructor & Destructor Documentation

◆ MemoryPool() [1/2]

Nz::MemoryPool::MemoryPool ( unsigned int  blockSize,
unsigned int  size = 1024,
bool  canGrow = true 
)
inline

Constructs a MemoryPool object.

Parameters
blockSizeSize of blocks that will be allocated
sizeSize of the pool
canGrowDetermine if the pool can allocate more memory

◆ MemoryPool() [2/2]

Nz::MemoryPool::MemoryPool ( MemoryPool &&  pool)
inlinenoexcept

Constructs a MemoryPool object by move semantic.

Parameters
poolMemoryPool to move into this

Member Function Documentation

◆ Allocate()

void * Nz::MemoryPool::Allocate ( unsigned int  size)
inline

Allocates enough memory for the size and returns a pointer to it.

Returns
A pointer to memory allocated
Parameters
sizeSize to allocate
Remarks
If the size is greather than the blockSize of pool, new operator is called

◆ Delete()

template<typename T >
void Nz::MemoryPool::Delete ( T *  ptr)

Deletes the memory represented by the poiner.

Calls the destructor of the object before releasing it

Remarks
If ptr is null, nothing is done

◆ Free()

void Nz::MemoryPool::Free ( void *  ptr)
inline

Frees the memory represented by the poiner.

If the pool gets empty after the call and we are the child of another pool, we commit suicide. If the pointer does not own to a block of the pool, operator delete is called

Remarks
Throws a std::runtime_error if pointer does not point to an element of the pool with NAZARA_CORE_SAFE defined
If ptr is null, nothing is done

◆ GetBlockSize()

unsigned int Nz::MemoryPool::GetBlockSize ( ) const
inline

Gets the block size.

Returns
Size of the blocks

◆ GetFreeBlocks()

unsigned int Nz::MemoryPool::GetFreeBlocks ( ) const
inline

Gets the number of free blocks.

Returns
Number of free blocks in the pool

◆ GetSize()

unsigned int Nz::MemoryPool::GetSize ( ) const
inline

Gets the pool size.

Returns
Size of the pool

◆ New()

template<typename T , typename... Args>
T * Nz::MemoryPool::New ( Args &&...  args)
inline

Creates a new value of type T with arguments.

Returns
Pointer to the allocated object
Parameters
argsArguments for the new object
Remarks
Constructs inplace in the pool

◆ operator=()

MemoryPool & Nz::MemoryPool::operator= ( MemoryPool &&  pool)
inlinenoexcept

Assigns the content of another pool by move semantic.

Returns
A reference to this
Parameters
poolOther pool to move into this

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