OpenBarnyard
 
Loading...
Searching...
No Matches
T2GenericObjectPool Class Reference

#include <T2ObjectPool.h>

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

Classes

struct  UnusedObject
 

Public Member Functions

virtual ~T2GenericObjectPool ()=default
 

Protected Member Functions

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
 
- Protected Member Functions inherited from T2Allocator
virtual size_t GetUsedSize () const =0
 
virtual size_t GetCapacity () const =0
 
template<class T, class... Args>
T * New (Args &&... args)
 
template<class T>
void Delete (T *ptr)
 

Protected Attributes

UnusedObjectm_pHead
 

Detailed Description

Definition at line 8 of file T2ObjectPool.h.

Constructor & Destructor Documentation

◆ ~T2GenericObjectPool()

virtual T2GenericObjectPool::~T2GenericObjectPool ( )
virtualdefault

Member Function Documentation

◆ CanAllocate()

virtual TBOOL T2GenericObjectPool::CanAllocate ( TSIZE size) const
inlineprotectedvirtual

Implements T2Allocator.

Definition at line 35 of file T2ObjectPool.h.

36 {
37 return m_pHead != TNULL;
38 }
#define TNULL
Definition Typedefs.h:23
UnusedObject * m_pHead

◆ Free()

virtual void T2GenericObjectPool::Free ( void * a_pPtr)
inlineprotectedvirtual

Implements T2Allocator.

Definition at line 30 of file T2ObjectPool.h.

31 {
33 }
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
void ReturnObject(UnusedObject *a_pObject)

◆ GetNumFreeObjects()

TUINT T2GenericObjectPool::GetNumFreeObjects ( ) const
inlineprotected

Definition at line 85 of file T2ObjectPool.h.

86 {
87 TUINT uiNumber = 0;
88 for ( auto it = m_pHead; it != TNULL; it = it->pNextObject, uiNumber++ )
89 ;
90
91 return uiNumber;
92 }
unsigned int TUINT
Definition Typedefs.h:8

◆ GetObject()

UnusedObject * T2GenericObjectPool::GetObject ( )
inlineprotected

Definition at line 72 of file T2ObjectPool.h.

73 {
74 UnusedObject* pNode = m_pHead;
75 m_pHead = m_pHead->pNextObject;
76 return pNode;
77 }

◆ Initialise()

void T2GenericObjectPool::Initialise ( UnusedObject * a_pObjects,
TUINT a_uiMaxNumber,
TUINT a_uiObjectSize )
inlineprotected

Definition at line 56 of file T2ObjectPool.h.

57 {
58 TASSERT( a_uiMaxNumber > 1 );
59 m_pHead = a_pObjects;
60 UnusedObject* pObject = a_pObjects;
61
62 for ( TUINT i = a_uiMaxNumber - 1; i != 0; i-- )
63 {
64 UnusedObject* pNext = TREINTERPRETCAST( UnusedObject*, TREINTERPRETCAST( TUINTPTR, pObject ) + a_uiObjectSize );
65 pObject->pNextObject = pNext;
66 pObject = pNext;
67 }
68
69 pObject->pNextObject = TNULL;
70 }
#define TASSERT(X,...)
Definition Defines.h:138
#define TREINTERPRETCAST(TYPE, VALUE)
Definition Defines.h:68
uintptr_t TUINTPTR
Definition Typedefs.h:18

◆ Malloc() [1/2]

virtual void * T2GenericObjectPool::Malloc ( TSIZE a_uiSize)
inlineprotectedvirtual

Implements T2Allocator.

Definition at line 25 of file T2ObjectPool.h.

26 {
27 return GetObject();
28 }
UnusedObject * GetObject()

◆ Malloc() [2/2]

virtual void * T2GenericObjectPool::Malloc ( TSIZE a_uiSize,
TSIZE a_uiAlignment )
inlineprotectedvirtual

Implements T2Allocator.

Definition at line 20 of file T2ObjectPool.h.

21 {
22 return TNULL;
23 }

◆ ReturnObject()

void T2GenericObjectPool::ReturnObject ( UnusedObject * a_pObject)
inlineprotected

Definition at line 79 of file T2ObjectPool.h.

80 {
81 a_pObject->pNextObject = m_pHead;
82 m_pHead = a_pObject;
83 }

◆ TryMalloc() [1/2]

virtual void * T2GenericObjectPool::TryMalloc ( TSIZE size)
inlineprotectedvirtual

Implements T2Allocator.

Definition at line 45 of file T2ObjectPool.h.

46 {
47 if ( m_pHead != TNULL )
48 {
49 return GetObject();
50 }
51
52 return TNULL;
53 }

◆ TryMalloc() [2/2]

virtual void * T2GenericObjectPool::TryMalloc ( TSIZE size,
TSIZE alignment )
inlineprotectedvirtual

Implements T2Allocator.

Definition at line 40 of file T2ObjectPool.h.

41 {
42 return TNULL;
43 }

Member Data Documentation

◆ m_pHead

UnusedObject* T2GenericObjectPool::m_pHead
protected

Definition at line 95 of file T2ObjectPool.h.


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