gwnavruntime/kernel/HeapMH/HeapMH_FreeBin.h Source File
Go to the documentation of this file.
18 #ifndef INC_KY_Kernel_HeapMH_FreeBin_H
19 #define INC_KY_Kernel_HeapMH_FreeBin_H
23 namespace Kaim {
namespace HeapMH {
35 #ifdef KY_64BIT_POINTERS
36 enum { MinBlocks = 2 };
38 enum { MinBlocks = 1 };
45 UPInt GetBlocks()
const
47 return (Prev & 0xF) | ((Next & 0xF) << 4);
50 UPInt GetBytes()
const
52 return GetBlocks() << PageMH::UnitShift;
55 UPInt GetPrevBlocks()
const
57 const UPInt* tail = ((
const UPInt*)
this) - 2;
58 return (tail[0] & 0xF) | ((tail[1] & 0xF) << 4);
61 UPInt GetPrevBytes()
const
63 return GetPrevBlocks() << PageMH::UnitShift;
66 void SetBlocks(UPInt blocks)
68 UPInt bytes = blocks << PageMH::UnitShift;
69 UPInt* tail = ((UPInt*)
this) + bytes /
sizeof(UPInt) - 2;
70 tail[0] = Prev = (Prev & ~UPInt(0xF)) | (blocks & 0xF);
71 tail[1] = Next = (Next & ~UPInt(0xF)) | (blocks >> 4);
74 void SetBytes(UPInt bytes)
76 UPInt blocks = bytes >> PageMH::UnitShift;
77 UPInt* tail = ((UPInt*)
this) + bytes /
sizeof(UPInt) - 2;
78 tail[0] = Prev = (Prev & ~UPInt(0xF)) | (blocks & 0xF);
79 tail[1] = Next = (Next & ~UPInt(0xF)) | (blocks >> 4);
84 return (GetBlocks() > MinBlocks) ? Page : 0;
87 void SetPage(PageMH* page)
89 if (GetBlocks() > MinBlocks)
93 BinNodeMH* GetPrev()
const {
return (BinNodeMH*)(Prev & ~UPInt(0xF)); }
94 BinNodeMH* GetNext()
const {
return (BinNodeMH*)(Next & ~UPInt(0xF)); }
96 void SetPrev(BinNodeMH* prev) { Prev = UPInt(prev) | (Prev & 0xF); }
97 void SetNext(BinNodeMH* next) { Next = UPInt(next) | (Next & 0xF); }
99 static BinNodeMH* MakeNode(UByte* start, UPInt bytes, PageMH* page)
101 BinNodeMH* node = (BinNodeMH*)start;
102 node->SetBytes(bytes);
112 enum { BinSize = 8*
sizeof(UPInt) };
118 void Push(UByte* node);
119 void Pull(UByte* node);
121 BinNodeMH* PullBest(UPInt blocks);
122 BinNodeMH* PullBest(UPInt blocks, UPInt alignMask);
124 void Merge(UByte* node, UPInt bytes,
bool left,
bool right, PageMH* page);
126 static UByte* GetAlignedPtr(UByte* start, UPInt alignMask);
127 static bool AlignmentIsOK(
const BinNodeMH* node, UPInt blocks, UPInt alignMask);
130 void pushNode(UPInt idx, BinNodeMH* node);
131 void pullNode(UPInt idx, BinNodeMH* node);
133 BinNodeMH* findAligned(BinNodeMH* root, UPInt blocks, UPInt alignMask);
136 BinNodeMH* getPrevAdjacent(UByte* node)
const;
137 BinNodeMH* getNextAdjacent(UByte* node)
const;
141 BinNodeMH* Roots[BinSize];
Definition: gamekitcrowddispersion.h:20