17 #ifndef INC_KY_Kernel_HeapPT_AllocEngine_H
18 #define INC_KY_Kernel_HeapPT_AllocEngine_H
25 namespace Kaim {
namespace HeapPT {
32 UPInt DynamicGranularity;
41 struct TinyBlock : ListNode<TinyBlock>
43 HeapSegment* pSegment;
47 typedef List<HeapSegment> SegmentListType;
48 typedef List<TinyBlock> TinyListType;
52 AllocEngine(SysAllocPaged* sysAlloc,
55 UPInt minAlignSize=16,
56 UPInt granularity=8*1024,
58 UPInt internalThreshold=128*1024,
63 bool IsValid()
const {
return Valid; }
65 UPInt SetLimit(UPInt lim);
66 void SetLimitHandler(
void* handler) { pLimHandler = handler; }
74 void* Alloc(UPInt size);
75 void* Alloc(UPInt size, UPInt alignSize);
76 void* Realloc(HeapSegment* seg,
void* oldPtr, UPInt newSize);
77 void Free(HeapSegment* seg,
void* ptr);
79 void* Realloc(
void* oldPtr, UPInt newSize);
82 UPInt GetUsableSize(
const void* ptr);
83 UPInt GetUsableSize(HeapSegment* seg,
const void* ptr);
85 UPInt GetFootprint()
const;
86 UPInt GetUsedSpace()
const;
88 void ReleaseCachedMem();
91 void VisitMem(MemVisitor* visitor,
92 unsigned flags = MemVisitor::VF_Heap)
const;
94 void VisitSegments(SegVisitor* visitor)
const;
96 void GetHeapOtherStats(HeapOtherStats* otherStats)
const;
98 void CheckIntegrity()
const
100 Allocator.CheckIntegrity();
105 static void compilerAsserts();
107 HeapSegment* allocSegment(
unsigned segType, UPInt size, UPInt sysAlignment,
108 UPInt bookkeepingSize,
bool* limHandlerOK);
110 HeapSegment* allocSegmentNoGranulator(UPInt dataSize, UPInt alignment,
bool* limHandlerOK);
112 HeapSegment* allocSegmentLocked(
unsigned segType, UPInt size, UPInt sysAlignment,
113 UPInt bookkeepingSize,
bool* limHandlerOK);
115 void freeSegment(HeapSegment* seg);
116 void freeSegmentLocked(HeapSegment* seg);
118 UPInt calcDynaSize()
const;
119 HeapSegment* allocSegmentBitSet(UPInt size, UPInt alignSize,
123 HeapSegment* allocSegmentBitSet(UPInt size, UPInt alignSize,
bool* limHandlerOK);
125 void freeSegmentBitSet(HeapSegment* seg);
127 void* allocSysDirect(UPInt dataSize, UPInt alignSize);
128 void* reallocSysDirect(HeapSegment* seg,
void* oldPtr, UPInt newSize);
130 void* reallocGeneral(HeapSegment* seg,
void* oldPtr,
131 UPInt oldSize, UPInt newSize,
134 void* allocBitSet(UPInt size);
135 void* allocBitSet(UPInt size, UPInt alignSize);
137 void* allocSegmentTiny(
unsigned idx);
138 void releaseSegmentTiny(HeapSegment* seg);
139 void freeSegmentTiny(HeapSegment* seg);
140 void* allocTiny(
unsigned sizeIdx);
141 void freeTiny(HeapSegment* seg, TinyBlock* ptr);
146 SysAllocPaged* pSysAlloc;
147 Bookkeeper* pBookkeeper;
150 AllocBitSet2 Allocator;
151 SegmentListType SegmentList;
152 TinyListType TinyBlocks[Heap_TinyBinSize];
153 bool AllowTinyBlocks;
157 UPInt SysGranularity;
161 UPInt SysDirectThreshold;
164 UPInt SysDirectSpace;
165 HeapSegment* pCachedBSeg;
166 HeapSegment* pCachedTSeg;
Definition: gamekitcrowddispersion.h:20