|
wavelength 1.0.0
|
Region of memory that hands out word-aligned blocks from a free list, best fit first. More...
#include <heap.h>
Public Member Functions | |
| 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 | InsertFreeBlock (FreeBlock *pBlock, int nSizeWords, FreeBlock *pPrev, FreeBlock *pNext) |
| Make a free block of a region and link it between two free blocks. | |
| void | GetInfo (int *pnBlocks, int *pnFreeBytes, int *pnBiggest) |
| Report the free blocks. | |
| void | Resize (int nSizeWords) |
| Change the size of the heap, growing or shrinking its last free block. | |
| void * | Alloc (int nSizeWords, const char *pszTag, int nAlignShift, int *pnSizeWords) |
| Hand out a block from the smallest free block that fits. | |
| void * | Realloc (void *pData, int nSizeWords, int *pnSizeWords) |
| Shrink a block of the heap in place, returning its spare words. | |
| void | FindNeighbors (void *pAddress, FreeBlock **ppPrev, FreeBlock **ppNext) |
| Find the free blocks on each side of an address. | |
| bool | Free (void *pData) |
| Return a block to the free list, merging it with its free neighbours. | |
| void | Print (PrnStream &stream, bool bSummary) |
| Write the blocks of the heap in address order. | |
| const char * | Name () const |
| Report the name of the heap. | |
| void | Compact (int nByteBudget, bool bStrict) |
| Move the handle blocks after the first free block that has some down over it, within a budget, and update the handles. | |
| int * | GetStart () const |
| int | GetSizeWords () const |
| const char * | GetName () const |
| void | Init (const char *name, int num, int *start, int sizeWords, bool flag) |
| Take over a region of memory as one free run. | |
| void | FreeBlockStats (int *numBlocks, int *freeBytes, int *biggestBlock) |
| Report the free runs. | |
| void | Resize (int sizeWords) |
| Grow or shrink the heap by moving its end. | |
| void * | Alloc (int sizeWords, const char *name, int alignBits, int *allocatedWords) |
| Allocate from the smallest free run that fits. | |
| bool | Free (void *mem) |
| Return an allocation to the free list, merging it with its neighbours. | |
| void | Print (PrnStream &stream, bool summary) |
| Print every run of the heap. | |
| int * | Start () const |
| Report the first word of the heap. | |
| int | SizeWords () const |
| Report the size of the heap. | |
| const char * | Name () const |
| Report the heap's name. | |
Region of memory that hands out word-aligned blocks from a free list, best fit first.
Region of memory carved into allocations with a sorted free list.
The class is not polymorphic. The name is inferred. The heaps are entries of a table that MemRegisterHeap() fills, and PoolMemAlloc() allocates from the heap MemPushHeap() selected.
The object is 0x18 bytes. The memory manager keeps sixteen of them. The name is inferred from the assertions of the memory manager.
| void Heap::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.
| pszName | The name of the heap. |
| nNum | The index of the heap in the table. |
| pStart | The region. |
| nSizeWords | The size of the region in words. |
| bHandles | Non-zero for a heap of handle blocks Compact() may move. |
| void Heap::InsertFreeBlock | ( | FreeBlock * | pBlock, |
| int | nSizeWords, | ||
| FreeBlock * | pPrev, | ||
| FreeBlock * | pNext ) |
Make a free block of a region and link it between two free blocks.
| pBlock | The region. |
| nSizeWords | The size of the region in words. |
| pPrev | The free block before, or null for the head of the list. |
| pNext | The free block after, or null. |
| void Heap::GetInfo | ( | int * | pnBlocks, |
| int * | pnFreeBytes, | ||
| int * | pnBiggest ) |
Report the free blocks.
| pnBlocks | Receives the number of free blocks. |
| pnFreeBytes | Receives the free bytes. |
| pnBiggest | Receives the bytes of the biggest free block. |
| void Heap::Resize | ( | int | nSizeWords | ) |
Change the size of the heap, growing or shrinking its last free block.
The last free block is taken to end the heap.
| nSizeWords | The size in words. |
| void * Heap::Alloc | ( | int | nSizeWords, |
| const char * | pszTag, | ||
| int | nAlignShift, | ||
| int * | pnSizeWords ) |
Hand out a block from the smallest free block that fits.
Padding of 9 or more words before the aligned block, and spare words of 9 or more after it, go back to the free list. A failure is reported and then dereferences a null block.
| nSizeWords | The words the block needs, its header included. |
| pszTag | The allocation tag, which the report of a failure leaves out. |
| nAlignShift | The alignment of the data as a power of two of words. |
| pnSizeWords | Receives the words the block takes. |
| void * Heap::Realloc | ( | void * | pData, |
| int | nSizeWords, | ||
| int * | pnSizeWords ) |
Shrink a block of the heap in place, returning its spare words.
A block is never grown.
| pData | The data of the block. |
| nSizeWords | The words the data needs. |
| pnSizeWords | Receives the words the block takes. |
Find the free blocks on each side of an address.
| pAddress | The address. |
| ppPrev | Receives the last free block before the address, or null. |
| ppNext | Receives the first free block at or after the address, or null. |
| bool Heap::Free | ( | void * | pData | ) |
Return a block to the free list, merging it with its free neighbours.
| pData | The data of the block. |
| void Heap::Print | ( | PrnStream & | stream, |
| bool | bSummary ) |
Write the blocks of the heap in address order.
| stream | The stream to write to. |
| bSummary | Whether each run of allocated blocks is written as one line before each free block, rather than each allocated block on its own line. |
| const char * Heap::Name | ( | ) | const |
Report the name of the heap.
| void Heap::Compact | ( | int | nByteBudget, |
| bool | bStrict ) |
Move the handle blocks after the first free block that has some down over it, within a budget, and update the handles.
| nByteBudget | The most bytes to move. |
| bStrict | Whether a block that would cross the budget stays. |
|
inline |
|
inline |
|
inline |
| void Heap::Init | ( | const char * | name, |
| int | num, | ||
| int * | start, | ||
| int | sizeWords, | ||
| bool | flag ) |
Take over a region of memory as one free run.
The start is rounded up to 16 bytes, and the size shrinks by the words skipped.
| name | The heap's name. |
| num | The heap's index. |
| start | The first word of the region. |
| sizeWords | The size of the region in words. |
| flag | The third value of the heap's configuration entry. |
| void Heap::FreeBlockStats | ( | int * | numBlocks, |
| int * | freeBytes, | ||
| int * | biggestBlock ) |
Report the free runs.
| numBlocks | Receives the number of free runs. |
| freeBytes | Receives the bytes in all free runs. |
| biggestBlock | Receives the bytes in the largest free run. |
| void Heap::Resize | ( | int | sizeWords | ) |
Grow or shrink the heap by moving its end.
The last free run must end at the heap's end.
| sizeWords | The new size in words. |
| void * Heap::Alloc | ( | int | sizeWords, |
| const char * | name, | ||
| int | alignBits, | ||
| int * | allocatedWords ) |
Allocate from the smallest free run that fits.
A failure prints the heap's state through the diagnostic stream.
| sizeWords | The words wanted, the header included. |
| name | The allocation's name. The routine does not read it. |
| alignBits | The allocation is aligned to 1 << alignBits words. |
| allocatedWords | Receives the words taken, padding included. |
| bool Heap::Free | ( | void * | mem | ) |
Return an allocation to the free list, merging it with its neighbours.
| mem | The allocation. |
| void Heap::Print | ( | PrnStream & | stream, |
| bool | summary ) |
Print every run of the heap.
| stream | The destination. |
| summary | When set, runs of allocations print as one line each with their count and free runs print too. When clear, every allocation prints alone and free runs are omitted. |
|
inline |
Report the first word of the heap.
|
inline |
Report the size of the heap.
|
inline |
Report the heap's name.