resonance 1.0.1
Loading...
Searching...
No Matches
heap.h File Reference
#include <stdint.h>
Include dependency graph for heap.h:

Go to the source code of this file.

Classes

struct  HeapNode
 One node of a heap, which is the boundary tag in front of a block. More...
class  Heap
 Boundary-tagged heap over one contiguous block. More...

Functions

void HHeapDelete (Heap *pHeap)
 Release a heap's backing block.
void HHeapDump (Heap *pHeap, const char *pszPath)
 Write a heap's header, counters, timings, and every node to a file.
void HHeapLogBasicStats (Heap *pHeap)
 Write a heap's counters to the log and to the memory report.

Variables

constexpr int kHeapHeaderSize = 0x28
 The number of bytes the header occupies at the front of the block.
constexpr int kHeapNodePrologueSize = 8
 The number of bytes of a node that precede its payload.
constexpr int kHeapFreeNodeSize = 0x10
 The number of bytes a free node occupies, which is all four of its words.
constexpr int kHeapMinPayloadSize = 8
 The smallest payload a node may serve.
constexpr int kHeapPayloadAlignment = 8
 Every payload size is rounded up to a multiple of this.
constexpr int kHeapSplitThreshold = 0x18
 A remainder smaller than this is not worth splitting off.
constexpr unsigned kHeapFlagFirstFit = 0x1
 Take the first free node that fits rather than the smallest.
constexpr unsigned kHeapFlagBestFit = 0x2
 Take the smallest free node that fits.
constexpr unsigned kHeapFlagFatalWhenFull = 0x4
 Treat exhaustion as fatal rather than reporting a null block.
constexpr unsigned kHeapFlagOwnsBlock = 0x8000
 The heap allocated its own backing block and releases it when destroyed.
Heap * gpPythonHeap
 The one interpreter heap, built by Py_Initialize() over the whole of the zone called python.

Function Documentation

◆ HHeapDelete()

void HHeapDelete ( Heap * pHeap)

Release a heap's backing block.

Performs no work unless the heap allocated the block itself. The heap is not cleared first and must not be used afterwards.

Parameters
pHeapThe heap.
Ghidra address:
NTSC-U/C: 0x00552108
Ghidra address:
PAL: 0x00592748

◆ HHeapDump()

void HHeapDump ( Heap * pHeap,
const char * pszPath )

Write a heap's header, counters, timings, and every node to a file.

Performs no work when the file cannot be opened. The header and the counters also go to the log.

Parameters
pHeapThe heap.
pszPathThe file to write.
Ghidra address:
NTSC-U/C: 0x00551ec8
Ghidra address:
PAL: 0x00592508

◆ HHeapLogBasicStats()

void HHeapLogBasicStats ( Heap * pHeap)

Write a heap's counters to the log and to the memory report.

Parameters
pHeapThe heap.
Ghidra address:
NTSC-U/C: 0x00552218
Ghidra address:
PAL: 0x00592858

Variable Documentation

◆ kHeapHeaderSize

int kHeapHeaderSize = 0x28
constexpr

The number of bytes the header occupies at the front of the block.

The value is written as a constant rather than as sizeof(Heap) because it is the size on the 32-bit target, which is what every offset in this header records.

◆ kHeapNodePrologueSize

int kHeapNodePrologueSize = 8
constexpr

The number of bytes of a node that precede its payload.

◆ kHeapFreeNodeSize

int kHeapFreeNodeSize = 0x10
constexpr

The number of bytes a free node occupies, which is all four of its words.

◆ kHeapMinPayloadSize

int kHeapMinPayloadSize = 8
constexpr

The smallest payload a node may serve.

◆ kHeapPayloadAlignment

int kHeapPayloadAlignment = 8
constexpr

Every payload size is rounded up to a multiple of this.

◆ kHeapSplitThreshold

int kHeapSplitThreshold = 0x18
constexpr

A remainder smaller than this is not worth splitting off.

The threshold is the full 16-byte free node plus the smallest payload, so every free node the heap produces can serve at least one allocation.

◆ kHeapFlagFirstFit

unsigned kHeapFlagFirstFit = 0x1
constexpr

Take the first free node that fits rather than the smallest.

This is the default.

◆ kHeapFlagBestFit

unsigned kHeapFlagBestFit = 0x2
constexpr

Take the smallest free node that fits.

◆ kHeapFlagFatalWhenFull

unsigned kHeapFlagFatalWhenFull = 0x4
constexpr

Treat exhaustion as fatal rather than reporting a null block.

◆ kHeapFlagOwnsBlock

unsigned kHeapFlagOwnsBlock = 0x8000
constexpr

The heap allocated its own backing block and releases it when destroyed.

◆ gpPythonHeap

Heap* gpPythonHeap
extern

The one interpreter heap, built by Py_Initialize() over the whole of the zone called python.

Ghidra address:
NTSC-U/C: 0x00723998
Ghidra address:
PAL: 0x00767588