The Pedigree Project 0.1
Public Member Functions | Private Attributes | List of all members
ObjectPool< T, poolSize > Class Template Reference

#include <ObjectPool.h>

+ Inheritance diagram for ObjectPool< T, poolSize >:
+ Collaboration diagram for ObjectPool< T, poolSize >:

Public Member Functions

template<typename... Args>
T * allocate (Args... args)
 
template<typename... Args>
T * tryAllocate (Args... args)
 
void deallocate (T *object)
 

Private Attributes

Vector< T * > m_Pool
 
Spinlock m_Spinlock
 

Detailed Description

template<class T, size_t poolSize = 16>
class ObjectPool< T, poolSize >
Todo:
add a MemoryPressureHandler here.

ObjectPool manages a set of objects for rapid allocation and deallocation, which is particularly useful for objects which are used frequently (e.g. nodes in a list).

If no objects are available (none have been deallocated yet), new objects are allocated from the heap.

Definition at line 43 of file ObjectPool.h.

Constructor & Destructor Documentation

◆ ObjectPool()

template<class T , size_t poolSize = 16>
ObjectPool< T, poolSize >::ObjectPool ( )
inline

Definition at line 45 of file ObjectPool.h.

◆ ~ObjectPool()

template<class T , size_t poolSize = 16>
virtual ObjectPool< T, poolSize >::~ObjectPool ( )
inlinevirtual

Definition at line 54 of file ObjectPool.h.

Member Function Documentation

◆ allocate()

template<class T , size_t poolSize = 16>
template<typename... Args>
T * ObjectPool< T, poolSize >::allocate ( Args...  args)
inline

Definition at line 61 of file ObjectPool.h.

◆ deallocate()

template<class T , size_t poolSize = 16>
void ObjectPool< T, poolSize >::deallocate ( T *  object)
inline

Definition at line 94 of file ObjectPool.h.

◆ tryAllocate()

template<class T , size_t poolSize = 16>
template<typename... Args>
T * ObjectPool< T, poolSize >::tryAllocate ( Args...  args)
inline

Definition at line 80 of file ObjectPool.h.

Member Data Documentation

◆ m_Pool

template<class T , size_t poolSize = 16>
Vector<T*> ObjectPool< T, poolSize >::m_Pool
private

Definition at line 119 of file ObjectPool.h.

◆ m_Spinlock

template<class T , size_t poolSize = 16>
Spinlock ObjectPool< T, poolSize >::m_Spinlock
private

Definition at line 121 of file ObjectPool.h.


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