OpenBarnyard
 
Loading...
Searching...
No Matches
T2ObjectPool< T, MaxNumber, ObjectSize, Alignment > Class Template Reference

#include <T2ObjectPool.h>

Inheritance diagram for T2ObjectPool< T, MaxNumber, ObjectSize, Alignment >:
T2GenericObjectPool T2Allocator

Public Member Functions

 TSTATICASSERT (MaxNumber >=2)
 
 TSTATICASSERT (sizeof(T) >=sizeof(T2GenericObjectPool::UnusedObject))
 
 T2ObjectPool ()
 
template<class... Args>
T * NewObject (Args &&... args)
 
T * AllocateObject ()
 
void FreeObject (T *a_pObject)
 
void DeleteObject (T *a_pObject)
 
virtual TSIZE GetUsedSize () const OVERRIDE
 
virtual TSIZE GetCapacity () const OVERRIDE
 
virtual TBOOL IsAddressInPool (const void *a_pAddress) const
 
TBOOL CanAllocate () const
 

Additional Inherited Members

- Protected Member Functions inherited from T2GenericObjectPool
virtual void * Malloc (TSIZE a_uiSize, TSIZE a_uiAlignment) OVERRIDE
 
virtual void * Malloc (TSIZE a_uiSize) OVERRIDE
 
virtual void Free (void *a_pPtr) OVERRIDE
 
virtual TBOOL CanAllocate (TSIZE size) const OVERRIDE
 
virtual void * TryMalloc (TSIZE size, TSIZE alignment) OVERRIDE
 
virtual void * TryMalloc (TSIZE size) OVERRIDE
 
void Initialise (UnusedObject *a_pObjects, TUINT a_uiMaxNumber, TUINT a_uiObjectSize)
 
UnusedObjectGetObject ()
 
void ReturnObject (UnusedObject *a_pObject)
 
TUINT GetNumFreeObjects () const
 
virtual ~T2GenericObjectPool ()=default
 
- Protected Member Functions inherited from T2Allocator
template<class T, class... Args>
T * New (Args &&... args)
 
template<class T>
void Delete (T *ptr)
 
- Protected Attributes inherited from T2GenericObjectPool
UnusedObjectm_pHead
 

Detailed Description

template<class T, TUINT MaxNumber, TUINT ObjectSize = sizeof( T ), TUINT Alignment = alignof( T )>
class T2ObjectPool< T, MaxNumber, ObjectSize, Alignment >

Definition at line 99 of file T2ObjectPool.h.

Constructor & Destructor Documentation

◆ T2ObjectPool()

template<class T, TUINT MaxNumber, TUINT ObjectSize = sizeof( T ), TUINT Alignment = alignof( T )>
T2ObjectPool< T, MaxNumber, ObjectSize, Alignment >::T2ObjectPool ( )
inline

Definition at line 106 of file T2ObjectPool.h.

107 {
110 MaxNumber,
112 );
113 }
#define TREINTERPRETCAST(TYPE, VALUE)
Definition Defines.h:68
void Initialise(UnusedObject *a_pObjects, TUINT a_uiMaxNumber, TUINT a_uiObjectSize)

Member Function Documentation

◆ AllocateObject()

template<class T, TUINT MaxNumber, TUINT ObjectSize = sizeof( T ), TUINT Alignment = alignof( T )>
T * T2ObjectPool< T, MaxNumber, ObjectSize, Alignment >::AllocateObject ( )
inline

Definition at line 123 of file T2ObjectPool.h.

124 {
126 return TSTATICCAST( T, Malloc( ObjectSize ) );
127 }
#define TASSERT(X,...)
Definition Defines.h:138
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
virtual void * Malloc(TSIZE a_uiSize, TSIZE a_uiAlignment) OVERRIDE

◆ CanAllocate()

template<class T, TUINT MaxNumber, TUINT ObjectSize = sizeof( T ), TUINT Alignment = alignof( T )>
TBOOL T2ObjectPool< T, MaxNumber, ObjectSize, Alignment >::CanAllocate ( ) const
inline

Definition at line 158 of file T2ObjectPool.h.

virtual TBOOL CanAllocate(TSIZE size) const OVERRIDE

◆ DeleteObject()

template<class T, TUINT MaxNumber, TUINT ObjectSize = sizeof( T ), TUINT Alignment = alignof( T )>
void T2ObjectPool< T, MaxNumber, ObjectSize, Alignment >::DeleteObject ( T * a_pObject)
inline

Definition at line 135 of file T2ObjectPool.h.

136 {
138 a_pObject->~T();
139 Free( a_pObject );
140 }
virtual void Free(void *a_pPtr) OVERRIDE
virtual TBOOL IsAddressInPool(const void *a_pAddress) const

◆ FreeObject()

template<class T, TUINT MaxNumber, TUINT ObjectSize = sizeof( T ), TUINT Alignment = alignof( T )>
void T2ObjectPool< T, MaxNumber, ObjectSize, Alignment >::FreeObject ( T * a_pObject)
inline

Definition at line 129 of file T2ObjectPool.h.

130 {
132 Free( a_pObject );
133 }

◆ GetCapacity()

template<class T, TUINT MaxNumber, TUINT ObjectSize = sizeof( T ), TUINT Alignment = alignof( T )>
virtual TSIZE T2ObjectPool< T, MaxNumber, ObjectSize, Alignment >::GetCapacity ( ) const
inlinevirtual

Implements T2Allocator.

Definition at line 147 of file T2ObjectPool.h.

148 {
149 return MaxNumber * ObjectSize;
150 }

◆ GetUsedSize()

template<class T, TUINT MaxNumber, TUINT ObjectSize = sizeof( T ), TUINT Alignment = alignof( T )>
virtual TSIZE T2ObjectPool< T, MaxNumber, ObjectSize, Alignment >::GetUsedSize ( ) const
inlinevirtual

Implements T2Allocator.

Definition at line 142 of file T2ObjectPool.h.

143 {
144 return ( MaxNumber - GetNumFreeObjects() ) * ObjectSize;
145 }
TUINT GetNumFreeObjects() const

◆ IsAddressInPool()

template<class T, TUINT MaxNumber, TUINT ObjectSize = sizeof( T ), TUINT Alignment = alignof( T )>
virtual TBOOL T2ObjectPool< T, MaxNumber, ObjectSize, Alignment >::IsAddressInPool ( const void * a_pAddress) const
inlinevirtual

Definition at line 152 of file T2ObjectPool.h.

153 {
154 return ( TREINTERPRETCAST( TUINTPTR, this ) + sizeof( T2GenericObjectPool ) ) <= TREINTERPRETCAST( TUINTPTR, a_pAddress ) &&
156 }

◆ NewObject()

template<class T, TUINT MaxNumber, TUINT ObjectSize = sizeof( T ), TUINT Alignment = alignof( T )>
template<class... Args>
T * T2ObjectPool< T, MaxNumber, ObjectSize, Alignment >::NewObject ( Args &&... args)
inline

Definition at line 116 of file T2ObjectPool.h.

117 {
119 T* pValue = new ( Malloc( ObjectSize ) ) T( std::forward<Args>( args )... );
120 return pValue;
121 }

◆ TSTATICASSERT() [1/2]

template<class T, TUINT MaxNumber, TUINT ObjectSize = sizeof( T ), TUINT Alignment = alignof( T )>
T2ObjectPool< T, MaxNumber, ObjectSize, Alignment >::TSTATICASSERT ( MaxNumber >= 2)

◆ TSTATICASSERT() [2/2]

template<class T, TUINT MaxNumber, TUINT ObjectSize = sizeof( T ), TUINT Alignment = alignof( T )>
T2ObjectPool< T, MaxNumber, ObjectSize, Alignment >::TSTATICASSERT ( sizeof(T) >=sizeof(T2GenericObjectPool::UnusedObject) )

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