CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::ObjectPool< T, RawAllocator > Class Template Reference

#include <CeresEngine/Foundation/Container/ObjectPool.hpp>

Public Member Functions

 ObjectPool (const size_t chunkSize=defaultChunkSize)
 Create an object pool with chunkSize objects.
 
 ObjectPool (const ObjectPool< T > &other)=delete
 
ObjectPool< T > & operator= (const ObjectPool< T > &other)=delete
 
 ObjectPool (ObjectPool< T > &&other)=delete
 
ObjectPool< T > & operator= (ObjectPool< T > &&other)=delete
 
 ~ObjectPool ()
 Frees all the allocated objects.
 
template<typename... Args>
Tallocate (Args &&... args)
 Reserve an object for use.
 
void release (T *obj)
 Return the object to the pool.
 

Static Public Attributes

static const constexpr size_t defaultChunkSize = 32
 The default allocation chunk size.
 

Protected Member Functions

void allocateChunk ()
 

Private Attributes

StdAllocator< T, RawAllocatormAllocator
 The allocator used to allocate memory for objects.
 
size_t mChunkSize = defaultChunkSize
 The pool chunk size.
 
Queue< T * > mFreeList
 
Vector< T * > mAllObjects
 

Constructor & Destructor Documentation

◆ ObjectPool() [1/3]

template<typename T , typename RawAllocator = DefaultAllocator>
CeresEngine::ObjectPool< T, RawAllocator >::ObjectPool ( const size_t  chunkSize = defaultChunkSize)
inlineexplicit

Create an object pool with chunkSize objects.

Whenever the object pool runs out of objects, chunkSize more objects will be added to the pool. The pool only grows: objects are never removed from the pool (freed), until the pool is destroyed.

Throws invalid_argument if chunkSize is <= 0.

◆ ObjectPool() [2/3]

template<typename T , typename RawAllocator = DefaultAllocator>
CeresEngine::ObjectPool< T, RawAllocator >::ObjectPool ( const ObjectPool< T > &  other)
delete

◆ ObjectPool() [3/3]

template<typename T , typename RawAllocator = DefaultAllocator>
CeresEngine::ObjectPool< T, RawAllocator >::ObjectPool ( ObjectPool< T > &&  other)
delete

◆ ~ObjectPool()

template<typename T , typename RawAllocator = DefaultAllocator>
CeresEngine::ObjectPool< T, RawAllocator >::~ObjectPool ( )
inline

Frees all the allocated objects.

Invalidates any objects that have been acquired for use.

Member Function Documentation

◆ allocate()

template<typename T , typename RawAllocator = DefaultAllocator>
template<typename... Args>
T * CeresEngine::ObjectPool< T, RawAllocator >::allocate ( Args &&...  args)
inline

Reserve an object for use.

The reference to the object is invalidated if the object pool itself is freed.

Clients must not free the object!

Returns
A pointer to the allocated object

◆ allocateChunk()

template<typename T , typename RawAllocator = DefaultAllocator>
void CeresEngine::ObjectPool< T, RawAllocator >::allocateChunk ( )
inlineprotected

◆ operator=() [1/2]

template<typename T , typename RawAllocator = DefaultAllocator>
ObjectPool< T > & CeresEngine::ObjectPool< T, RawAllocator >::operator= ( const ObjectPool< T > &  other)
delete

◆ operator=() [2/2]

template<typename T , typename RawAllocator = DefaultAllocator>
ObjectPool< T > & CeresEngine::ObjectPool< T, RawAllocator >::operator= ( ObjectPool< T > &&  other)
delete

◆ release()

template<typename T , typename RawAllocator = DefaultAllocator>
void CeresEngine::ObjectPool< T, RawAllocator >::release ( T obj)
inline

Return the object to the pool.

Clients must not use the object after it has been returned to the pool.

Parameters
objA pointer to the object being released

Member Data Documentation

◆ defaultChunkSize

template<typename T , typename RawAllocator = DefaultAllocator>
const constexpr size_t CeresEngine::ObjectPool< T, RawAllocator >::defaultChunkSize = 32
inlinestaticconstexpr

The default allocation chunk size.

◆ mAllObjects

template<typename T , typename RawAllocator = DefaultAllocator>
Vector<T*> CeresEngine::ObjectPool< T, RawAllocator >::mAllObjects
private

◆ mAllocator

template<typename T , typename RawAllocator = DefaultAllocator>
StdAllocator<T, RawAllocator> CeresEngine::ObjectPool< T, RawAllocator >::mAllocator
private

The allocator used to allocate memory for objects.

◆ mChunkSize

template<typename T , typename RawAllocator = DefaultAllocator>
size_t CeresEngine::ObjectPool< T, RawAllocator >::mChunkSize = defaultChunkSize
private

The pool chunk size.

◆ mFreeList

template<typename T , typename RawAllocator = DefaultAllocator>
Queue<T*> CeresEngine::ObjectPool< T, RawAllocator >::mFreeList
private

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