gwnavruntime/kernel/HeapMH/HeapMH_FreeBin.h Source File
Go to the documentation of this file.
22 namespace Kaim {
namespace HeapMH {
34 #ifdef KY_64BIT_POINTERS
35 enum { MinBlocks = 2 };
37 enum { MinBlocks = 1 };
44 UPInt GetBlocks()
const
46 return (Prev & 0xF) | ((Next & 0xF) << 4);
49 UPInt GetBytes()
const
51 return GetBlocks() << PageMH::UnitShift;
54 UPInt GetPrevBlocks()
const
56 const UPInt* tail = ((
const UPInt*)
this) - 2;
57 return (tail[0] & 0xF) | ((tail[1] & 0xF) << 4);
60 UPInt GetPrevBytes()
const
62 return GetPrevBlocks() << PageMH::UnitShift;
65 void SetBlocks(UPInt blocks)
67 UPInt bytes = blocks << PageMH::UnitShift;
68 UPInt* tail = ((UPInt*)
this) + bytes /
sizeof(UPInt) - 2;
69 tail[0] = Prev = (Prev & ~UPInt(0xF)) | (blocks & 0xF);
70 tail[1] = Next = (Next & ~UPInt(0xF)) | (blocks >> 4);
73 void SetBytes(UPInt bytes)
75 UPInt blocks = bytes >> PageMH::UnitShift;
76 UPInt* tail = ((UPInt*)
this) + bytes /
sizeof(UPInt) - 2;
77 tail[0] = Prev = (Prev & ~UPInt(0xF)) | (blocks & 0xF);
78 tail[1] = Next = (Next & ~UPInt(0xF)) | (blocks >> 4);
83 return (GetBlocks() > MinBlocks) ? Page : 0;
86 void SetPage(PageMH* page)
88 if (GetBlocks() > MinBlocks)
92 BinNodeMH* GetPrev()
const {
return (BinNodeMH*)(Prev & ~UPInt(0xF)); }
93 BinNodeMH* GetNext()
const {
return (BinNodeMH*)(Next & ~UPInt(0xF)); }
95 void SetPrev(BinNodeMH* prev) { Prev = UPInt(prev) | (Prev & 0xF); }
96 void SetNext(BinNodeMH* next) { Next = UPInt(next) | (Next & 0xF); }
98 static BinNodeMH* MakeNode(
UByte* start, UPInt bytes, PageMH* page)
100 BinNodeMH* node = (BinNodeMH*)start;
101 node->SetBytes(bytes);
111 enum { BinSize = 8*
sizeof(UPInt) };
117 void Push(
UByte* node);
118 void Pull(
UByte* node);
120 BinNodeMH* PullBest(UPInt blocks);
121 BinNodeMH* PullBest(UPInt blocks, UPInt alignMask);
123 void Merge(
UByte* node, UPInt bytes,
bool left,
bool right, PageMH* page);
125 static UByte* GetAlignedPtr(
UByte* start, UPInt alignMask);
126 static bool AlignmentIsOK(
const BinNodeMH* node, UPInt blocks, UPInt alignMask);
129 void pushNode(UPInt idx, BinNodeMH* node);
130 void pullNode(UPInt idx, BinNodeMH* node);
132 BinNodeMH* findAligned(BinNodeMH* root, UPInt blocks, UPInt alignMask);
135 BinNodeMH* getPrevAdjacent(
UByte* node)
const;
136 BinNodeMH* getNextAdjacent(
UByte* node)
const;
140 BinNodeMH* Roots[BinSize];
std::uint8_t UByte
uint8_t
Definition: SF_Types.h:134
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17