Introduction
Downloads
Documentation
Tutorials
Pixie Lite
Forum

Home

MemoryPool< TYPE > Class Template Reference
[Containers]

MemoryPool for faster dynamic memory allocation. More...

List of all members.


Public Member Functions

 MemoryPool (int entriesPerBlock=64)
 ~MemoryPool ()
TYPE * Allocate ()
void Free (TYPE *object)
bool IsInUse () const

Detailed Description

template<class TYPE>
class MemoryPool< TYPE >

MemoryPool for faster dynamic memory allocation.

Author:
Mattias Gustavsson
Memory pools are very useful if you need to dynamically allocate and free many blocks of memory that are all the same size. A memory pool works by allocating larger chunks of memory, and dishing it out in smaller chunks as requested. When memory is freed, it is not released, but instead recycled to be used in future requests to allocate memory. Another advantage of memory pools is that blocks are kept closer to each other in memory, increasing cache coherency.

Definition at line 25 of file MemoryPool.h.


Constructor & Destructor Documentation

template<class TYPE >
MemoryPool< TYPE >::MemoryPool ( int  entriesPerBlock = 64  ) 

Constructor

Parameters:
entriesPerBlock The number of entries per block. By tweaking this value, better performance might be obtained. Things that rarely allocates from the memory pool can have a low value for this, but things doing many allocations are better off upping it.

Definition at line 11 of file MemoryPool.inl.

template<class TYPE >
MemoryPool< TYPE >::~MemoryPool (  ) 

Destructor

Definition at line 27 of file MemoryPool.inl.


Member Function Documentation

template<class TYPE >
TYPE * MemoryPool< TYPE >::Allocate (  ) 

Retrieves an unused entry from the memory pool. If there are no more unused entries left, a new block will be allocated.

Returns:
A pointer to an unused entry from the memory pool

Definition at line 125 of file MemoryPool.inl.

template<class TYPE>
void MemoryPool< TYPE >::Free ( TYPE *  object  ) 

Marks the specified entry contained in the memory pool as unused

Parameters:
object Memory pool entry to release

Definition at line 150 of file MemoryPool.inl.

template<class TYPE >
bool MemoryPool< TYPE >::IsInUse (  )  const

Determines if the memory pool is still in use, meaning that there are still entries of the pool being used/allocated.

Returns:
True if any of the entries of the memory pool is marked as used, False otherwise

Definition at line 179 of file MemoryPool.inl.



Pixie University and the Pixie Game Engine is created and managed by Mattias Gustavsson.
Reproduction/republishing of any material on this site without permission is strictly prohibited.