OpenBarnyard
 
Loading...
Searching...
No Matches
TFreeList.h
Go to the documentation of this file.
1#pragma once
2
3#define TDECLARE_FREELIST_ALLOCATOR( CLASS_NAME ) \
4public: \
5 TFORCEINLINE void* operator new( size_t s ) { return ms_oFreeList.New( sizeof( CLASS_NAME ) ); } \
6 TFORCEINLINE void* operator new( size_t s, void* where ) { return where; } \
7 \
8 TFORCEINLINE void operator delete( void* ptr ) { ms_oFreeList.Delete( ptr ); } \
9 TFORCEINLINE void operator delete( void* ptr, void* where ) { delete ptr; } \
10 \
11 static void SetupFreeList( TINT a_iCapacity, TINT a_iGrowSize ) \
12 { \
13 ms_oFreeList.SetCapacity( a_iCapacity ); \
14 ms_oFreeList.SetGrowSize( a_iGrowSize ); \
15 } \
16 \
17 static Toshi::TFreeList ms_oFreeList;
18
19#define TDEFINE_FREELIST_ALLOCATOR( CLASS_NAME ) \
20 Toshi::TFreeList CLASS_NAME::ms_oFreeList = Toshi::TFreeList( sizeof( CLASS_NAME ), 0, 8, #CLASS_NAME );
21
22#define TDEFINE_FREELIST_ALLOCATOR1( CLASS_NAME, GROW_SIZE ) \
23 Toshi::TFreeList CLASS_NAME::ms_oFreeList = Toshi::TFreeList( sizeof( CLASS_NAME ), 0, GROW_SIZE, #CLASS_NAME );
24
26
28{
29public:
30 struct Node
31 {
33 };
34
35public:
36 TFreeList( TUINT a_uiItemSize, TINT a_iInitialSize, TINT a_iGrowSize, const TCHAR* a_pchName );
37
38 Node* Allocate( TINT a_iNumber, TINT a_iSize );
39 void SetCapacity( TINT a_iNewCapacity );
40
41 TINT GetCapacity() const { return m_iCapacity; }
42 TINT GetGrowSize() const { return m_iGrowSize; }
43
44 void SetGrowSize( TINT a_iGrowSize ) { a_iGrowSize < 0 ? m_iGrowSize = 8 : m_iGrowSize = a_iGrowSize; }
45 void* New( TUINT a_uiSize );
46
47 void Delete( void* a_Ptr );
48
49private:
50 inline static TFreeList* ms_pLastList = TNULL;
51
52private:
53 TFreeList* m_pPrevList;
54 TINT m_iCapacity;
55 TUINT m_uiItemSize;
56 Node m_LastNode;
57 Node m_RootNode;
58 TINT m_iGrowSize;
59 TMemory::MemBlock* m_pMemoryHeap;
60};
61
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
unsigned int TUINT
Definition Typedefs.h:8
char TCHAR
Definition Typedefs.h:20
#define TNULL
Definition Typedefs.h:23
int TINT
Definition Typedefs.h:7
Represents a contiguous block of memory that can be allocated from.
Definition TMemory.h:101
Node * Allocate(TINT a_iNumber, TINT a_iSize)
Definition TFreeList.cpp:25
void Delete(void *a_Ptr)
Definition TFreeList.cpp:81
void SetCapacity(TINT a_iNewCapacity)
Definition TFreeList.cpp:50
TFreeList(TUINT a_uiItemSize, TINT a_iInitialSize, TINT a_iGrowSize, const TCHAR *a_pchName)
Definition TFreeList.cpp:12
TINT GetGrowSize() const
Definition TFreeList.h:42
void SetGrowSize(TINT a_iGrowSize)
Definition TFreeList.h:44
TINT GetCapacity() const
Definition TFreeList.h:41
void * New(TUINT a_uiSize)
Definition TFreeList.cpp:61