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

#include <TFreeList.h>

Classes

struct  Node
 

Public Member Functions

 TFreeList (TUINT a_uiItemSize, TINT a_iInitialSize, TINT a_iGrowSize, const TCHAR *a_pchName)
 
NodeAllocate (TINT a_iNumber, TINT a_iSize)
 
void SetCapacity (TINT a_iNewCapacity)
 
TINT GetCapacity () const
 
TINT GetGrowSize () const
 
void SetGrowSize (TINT a_iGrowSize)
 
void * New (TUINT a_uiSize)
 
void Delete (void *a_Ptr)
 

Detailed Description

Definition at line 27 of file TFreeList.h.

Constructor & Destructor Documentation

◆ TFreeList()

TFreeList::TFreeList ( TUINT a_uiItemSize,
TINT a_iInitialSize,
TINT a_iGrowSize,
const TCHAR * a_pchName )

Definition at line 12 of file TFreeList.cpp.

13{
14 m_uiItemSize = a_uiItemSize;
15 m_iCapacity = 0;
16 m_pMemoryHeap = TNULL;
17 TASSERT( m_iGrowSize >= 0 );
18 TASSERT( a_iInitialSize >= 0 );
19 SetGrowSize( a_iGrowSize );
20
21 m_pPrevList = ms_pLastList;
22 ms_pLastList = this;
23}
#define TASSERT(X,...)
Definition Defines.h:138
#define TNULL
Definition Typedefs.h:23
void SetGrowSize(TINT a_iGrowSize)
Definition TFreeList.h:44

Member Function Documentation

◆ Allocate()

TFreeList::Node * TFreeList::Allocate ( TINT a_iNumber,
TINT a_iSize )

Definition at line 25 of file TFreeList.cpp.

26{
27 TASSERT( a_iNumber > 0 );
28 m_iCapacity += a_iNumber;
29
30 Node* pNewNode = TREINTERPRETCAST( Node*, TMalloc( a_iNumber * a_iSize + sizeof( Node ), m_pMemoryHeap ) );
31
32 pNewNode->pNext = m_RootNode.pNext;
33 m_RootNode.pNext = pNewNode;
34
35 auto pData = pNewNode + 1;
36 Node* pNext = TNULL;
37
38 for ( TINT i = a_iNumber - 1; i != 0; i-- )
39 {
40 pData->pNext = pNext;
41 pNext = pData;
42
43 pData = TREINTERPRETCAST( Node*, TREINTERPRETCAST( uintptr_t, pData ) + a_iSize );
44 }
45
46 m_LastNode.pNext = pNext;
47 return pData;
48}
void * TMalloc(TSIZE a_uiSize, Toshi::TMemory::MemBlock *a_pMemBlock, const TCHAR *a_szFileName, TINT a_iLineNum)
Allocates memory from a specific memory block.
Definition TMemory.cpp:973
#define TREINTERPRETCAST(TYPE, VALUE)
Definition Defines.h:68
int TINT
Definition Typedefs.h:7

◆ Delete()

void TFreeList::Delete ( void * a_Ptr)

Definition at line 81 of file TFreeList.cpp.

82{
83 Node* pNode = TSTATICCAST( Node, a_Ptr );
84
85 if ( m_LastNode.pNext != TNULL )
86 {
87 pNode->pNext = m_LastNode.pNext;
88 m_LastNode.pNext = pNode;
89 }
90 else
91 {
92 m_LastNode.pNext = pNode;
93 pNode->pNext = TNULL;
94 }
95}
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69

◆ GetCapacity()

TINT TFreeList::GetCapacity ( ) const
inline

Definition at line 41 of file TFreeList.h.

41{ return m_iCapacity; }

◆ GetGrowSize()

TINT TFreeList::GetGrowSize ( ) const
inline

Definition at line 42 of file TFreeList.h.

42{ return m_iGrowSize; }

◆ New()

void * TFreeList::New ( TUINT a_uiSize)

Definition at line 61 of file TFreeList.cpp.

62{
63 if ( a_uiSize != m_uiItemSize )
64 {
65 return TMalloc( a_uiSize, TNULL );
66 }
67
68 auto pNode = m_LastNode.pNext;
69
70 if ( pNode != TNULL )
71 {
72 m_LastNode.pNext = pNode->pNext;
73 return pNode;
74 }
75 else
76 {
77 return Allocate( m_iGrowSize, a_uiSize );
78 }
79}
Node * Allocate(TINT a_iNumber, TINT a_iSize)
Definition TFreeList.cpp:25

◆ SetCapacity()

void TFreeList::SetCapacity ( TINT a_iNewCapacity)

Definition at line 50 of file TFreeList.cpp.

51{
52 if ( m_iCapacity < a_iNewCapacity )
53 {
54 auto pNode = Allocate( a_iNewCapacity - m_iCapacity, m_uiItemSize );
55
56 pNode->pNext = m_LastNode.pNext;
57 m_LastNode.pNext = pNode;
58 }
59}

◆ SetGrowSize()

void TFreeList::SetGrowSize ( TINT a_iGrowSize)
inline

Definition at line 44 of file TFreeList.h.

44{ a_iGrowSize < 0 ? m_iGrowSize = 8 : m_iGrowSize = a_iGrowSize; }

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