21 template<
typename T,
typename RawAllocator = DefaultAllocator>
class ObjectPool {
52 throw std::invalid_argument(
"chunk size must be positive");
76 template<
typename... Args>
T*
allocate(Args&&... args) {
83 return new(
obj)
T(std::forward<Args>(args)...);
#define CE_NO_UNIQUE_ADDRESS
Definition Macros.hpp:407
Definition ObjectPool.hpp:21
Queue< T * > mFreeList
Definition ObjectPool.hpp:36
void allocateChunk()
Definition ObjectPool.hpp:96
void release(T *obj)
Return the object to the pool.
Definition ObjectPool.hpp:89
ObjectPool< T > & operator=(ObjectPool< T > &&other)=delete
ObjectPool(ObjectPool< T > &&other)=delete
~ObjectPool()
Frees all the allocated objects.
Definition ObjectPool.hpp:63
ObjectPool(const size_t chunkSize=defaultChunkSize)
Create an object pool with chunkSize objects.
Definition ObjectPool.hpp:50
Vector< T * > mAllObjects
Definition ObjectPool.hpp:41
StdAllocator< T, RawAllocator > mAllocator
The allocator used to allocate memory for objects.
Definition ObjectPool.hpp:29
ObjectPool(const ObjectPool< T > &other)=delete
T * allocate(Args &&... args)
Reserve an object for use.
Definition ObjectPool.hpp:76
ObjectPool< T > & operator=(const ObjectPool< T > &other)=delete
static const constexpr size_t defaultChunkSize
The default allocation chunk size.
Definition ObjectPool.hpp:24
size_t mChunkSize
The pool chunk size.
Definition ObjectPool.hpp:32
Definition Application.hpp:19
std::queue< T, Container > Queue
The Queue class is a container adapter that gives the programmer the functionality of a queue - speci...
Definition Queue.hpp:19
foonathan::memory::std_allocator< T, RawAllocator > StdAllocator
Definition Allocator.hpp:225
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
constexpr ForEachAlgorithmFunctor for_each
Applies a function to a range of elements.
Definition ForEach.hpp:123
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25