wavelength 1.0.0
Loading...
Searching...
No Matches
heap.h
Go to the documentation of this file.
1#pragma once
2
3#include "os/prnstream.h"
4
10class FreeBlock {
11public:
20 bool Merge(FreeBlock *pNext);
21
24};
25
28 unsigned int mSizeWords : 24;
29 unsigned int mPadWords : 8;
30};
31
38class Heap {
39public:
52 void Init(const char *pszName, int nNum, int *pStart, int nSizeWords, int bHandles);
53
64 void InsertFreeBlock(FreeBlock *pBlock, int nSizeWords, FreeBlock *pPrev, FreeBlock *pNext);
65
75 void GetInfo(int *pnBlocks, int *pnFreeBytes, int *pnBiggest);
76
86 void Resize(int nSizeWords);
87
102 void *Alloc(int nSizeWords, const char *pszTag, int nAlignShift, int *pnSizeWords);
103
116 void *Realloc(void *pData, int nSizeWords, int *pnSizeWords);
117
127 void FindNeighbors(void *pAddress, FreeBlock **ppPrev, FreeBlock **ppNext);
128
137 bool Free(void *pData);
138
148 void Print(PrnStream &stream, bool bSummary);
149
157 const char *Name() const;
158
168 void Compact(int nByteBudget, bool bStrict);
169
171 int *GetStart() const {
172 return mStart;
173 }
174
176 int GetSizeWords() const {
177 return mSizeWords;
178 }
179
181 const char *GetName() const {
182 return mName;
183 }
184
185private:
186 FreeBlock *mFreeList;
187 int *mStart;
188 const char *mName;
189 int mSizeWords;
190 int mNum;
191 int mHandles;
192};
Free block of a Heap, a node of the heap's free list in address order.
Definition heap.h:10
int mSizeWords
Definition heap.h:22
bool Merge(FreeBlock *pNext)
Absorb the free block that starts where this one ends.
FreeBlock * mNext
Definition heap.h:23
Region of memory that hands out word-aligned blocks from a free list, best fit first.
Definition heap.h:38
void FindNeighbors(void *pAddress, FreeBlock **ppPrev, FreeBlock **ppNext)
Find the free blocks on each side of an address.
int * GetStart() const
Definition heap.h:171
void Resize(int nSizeWords)
Change the size of the heap, growing or shrinking its last free block.
void Print(PrnStream &stream, bool bSummary)
Write the blocks of the heap in address order.
void Compact(int nByteBudget, bool bStrict)
Move the handle blocks after the first free block that has some down over it, within a budget,...
void * Realloc(void *pData, int nSizeWords, int *pnSizeWords)
Shrink a block of the heap in place, returning its spare words.
void InsertFreeBlock(FreeBlock *pBlock, int nSizeWords, FreeBlock *pPrev, FreeBlock *pNext)
Make a free block of a region and link it between two free blocks.
int GetSizeWords() const
Definition heap.h:176
void GetInfo(int *pnBlocks, int *pnFreeBytes, int *pnBiggest)
Report the free blocks.
const char * Name() const
Report the name of the heap.
const char * GetName() const
Definition heap.h:181
bool Free(void *pData)
Return a block to the free list, merging it with its free neighbours.
void Init(const char *pszName, int nNum, int *pStart, int nSizeWords, int bHandles)
Take over a region as one free block, starting at the first word whose next word is 16-byte aligned.
void * Alloc(int nSizeWords, const char *pszTag, int nAlignShift, int *pnSizeWords)
Hand out a block from the smallest free block that fits.
Text output stream.
Definition prnstream.h:16
The word before each block Heap::Alloc() hands out.
Definition heap.h:27
unsigned int mSizeWords
Definition heap.h:28
unsigned int mPadWords
Definition heap.h:29