21 #ifndef INC_KY_Kernel_Memory_AllocAddr_H
22 #define INC_KY_Kernel_Memory_AllocAddr_H
31 struct AllocAddrNode : ListNode<AllocAddrNode>
33 AllocAddrNode* AddrParent;
34 AllocAddrNode* AddrChild[2];
35 AllocAddrNode* SizeParent;
36 AllocAddrNode* SizeChild[2];
52 typedef AllocAddrNode FreeNode;
58 static UPInt GetKey (
const FreeNode* n) {
return n->Size; }
59 static FreeNode* GetChild ( FreeNode* n, UPInt i) {
return n->SizeChild[i]; }
60 static const FreeNode* GetChild (
const FreeNode* n, UPInt i) {
return n->SizeChild[i]; }
61 static FreeNode** GetChildPtr( FreeNode* n, UPInt i) {
return &n->SizeChild[i]; }
63 static FreeNode* GetParent ( FreeNode* n) {
return n->SizeParent; }
64 static const FreeNode* GetParent (
const FreeNode* n) {
return n->SizeParent; }
66 static void SetParent (FreeNode* n, FreeNode* p) { n->SizeParent = p; }
67 static void SetChild (FreeNode* n, UPInt i, FreeNode* c) { n->SizeChild[i] = c; }
68 static void ClearLinks(FreeNode* n) { n->SizeParent = n->SizeChild[0] = n->SizeChild[1] = 0; }
74 static UPInt GetKey (
const FreeNode* n) {
return n->Addr; }
75 static FreeNode* GetChild ( FreeNode* n, UPInt i) {
return n->AddrChild[i]; }
76 static const FreeNode* GetChild (
const FreeNode* n, UPInt i) {
return n->AddrChild[i]; }
77 static FreeNode** GetChildPtr( FreeNode* n, UPInt i) {
return &n->AddrChild[i]; }
79 static FreeNode* GetParent ( FreeNode* n) {
return n->AddrParent; }
80 static const FreeNode* GetParent (
const FreeNode* n) {
return n->AddrParent; }
82 static void SetParent (FreeNode* n, FreeNode* p) { n->AddrParent = p; }
83 static void SetChild (FreeNode* n, UPInt i, FreeNode* c) { n->AddrChild[i] = c; }
84 static void ClearLinks(FreeNode* n) { n->AddrParent = n->AddrChild[0] = n->AddrChild[1] = 0; }
88 AllocAddr(MemoryHeap* nodeHeap);
89 AllocAddr(MemoryHeap* nodeHeap, UPInt start, UPInt size);
97 void AddSegment(UPInt addr, UPInt size);
98 void RemoveSegment(UPInt addr, UPInt size);
102 UPInt Alloc(UPInt size);
107 UPInt Free(UPInt addr, UPInt size);
110 UPInt GetLargestAvailable()
112 const FreeNode* node = SizeTree.FindBestLeEq(~UPInt(0));
113 return node ? node->Size : 0;
118 typedef RadixTreeMulti<FreeNode, SizeAccessor> SizeTreeType;
119 typedef RadixTree <FreeNode, AddrAccessor> AddrTreeType;
123 void pushNode(FreeNode* node, UPInt addr, UPInt size);
124 void pullNode(FreeNode* node);
125 FreeNode* pullBest(UPInt size);
126 void splitNode(FreeNode* node, UPInt addr, UPInt size);
127 UPInt mergeNodes(FreeNode* prev, FreeNode* next, UPInt addr, UPInt size);
131 MemoryHeap* pNodeHeap;
132 SizeTreeType SizeTree;
133 AddrTreeType AddrTree;
Definition: gamekitcrowddispersion.h:20