wavelength 1.0.0
Loading...
Searching...
No Matches
mem.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
Include dependency graph for mem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void * PoolAlloc (int nSize, int nBlockSize, const char *pszTag, int nUnused)
 Allocate a block from the small-block pool and bill it to a tag.
void PoolFree (int nSize, void *pBlock)
 Return a block to the small-block pool.
void PoolReport (PrnStream &stream)
 Write the use of the small-block pool.
int MemGetHeap ()
 Report the heap that PoolMemAlloc() allocates from, the top of the heap stack.
void MemHeapInfo (int nHeap, int *pnBlocks, int *pnFreeBytes, int *pnBiggest)
 Report the free blocks of a heap.
int MemRegisterHeap (const char *pszName, int *pStart, int nSizeWords, int bHandles)
 Add a heap to the table.
void MemSetHeapSize (int nHeap, int nSizeWords)
 Change the size of a heap.
void MemPushHeap (int nHeap)
 Make a heap the one PoolMemAlloc() allocates from, until MemPopHeap().
void MemPopHeap ()
 Undo the latest MemPushHeap().
void MemInit ()
 Take the memory from the end of the C library's heap to 0x1f70000 as the heap main, and start the memory tracker when it is available.
void * MemRealloc (void *pBlock, int nBytes)
 Shrink a block in place.
int MemNumHeaps ()
 Report the number of heaps.
void MemPrintHeap (int nHeap, PrnStream &stream)
 Write each block of a heap.
void * MemOrPoolAlloc (int nSize, const char *pszTag)
 Allocate a block of up to 128 bytes from the pool of fixed-size blocks, and a larger block from the pool heaps.
void MemOrPoolFree (int nSize, void *pBlock)
 Return a block MemOrPoolAlloc() handed out.
int MemFindHeap (const char *pszName)
 Look up a heap by its configured name.
void MemCompact (int nHeap, int nByteBudget, bool bStrictBudget)
 Move live blocks of one heap together to merge its free space.
void * PoolMemAlloc (int nSize, const char *pszTag, int nAlign)
 Allocate a block from the pool heaps and bill it to a tag.
void PoolMemFree (void *pBlock)
 Return a block PoolMemAlloc() handed out to the pool heap that owns it.
void MemConfigureHeaps ()
 Set the heaps up from the system configuration.
void MemTerminate ()
 Shut the heaps down.
void MemPoll ()
 Record the state of every tracked heap, once per frame.

Variables

int g_nMemTrackingEnabled
 Non-zero while the memory tracker records allocations.
int g_nTrackStl
 Non-zero when the memory tracker bills STL allocations to their container, from track_stl.

Function Documentation

◆ PoolAlloc()

void * PoolAlloc ( int nSize,
int nBlockSize,
const char * pszTag,
int nUnused )

Allocate a block from the small-block pool and bill it to a tag.

The pool is created on first use.

Parameters
nSizeThe block size in bytes, which selects the node size of the pool.
nBlockSizeNot used.
pszTagThe tag to bill the allocation to.
nUnusedNot used.
Returns
The block.
Ghidra address:
NTSC-U/C: 0x0029e010
Ghidra address:
PAL: 0x002a7cd8

◆ PoolFree()

void PoolFree ( int nSize,
void * pBlock )

Return a block to the small-block pool.

Parameters
nSizeThe block size given to PoolAlloc().
pBlockThe block.
Ghidra address:
NTSC-U/C: 0x0029e0a8
Ghidra address:
PAL: 0x002a7d70

◆ PoolReport()

void PoolReport ( PrnStream & stream)

Write the use of the small-block pool.

The name is inferred.

Parameters
streamThe stream to write to.
Ghidra address:
NTSC-U/C: 0x0029e100
Ghidra address:
PAL: 0x002a7dc8

◆ MemGetHeap()

int MemGetHeap ( )

Report the heap that PoolMemAlloc() allocates from, the top of the heap stack.

The name is inferred.

Returns
The index of the heap.
Ghidra address:
NTSC-U/C: 0x00299de0
Ghidra address:
PAL: 0x002a39e0

◆ MemHeapInfo()

void MemHeapInfo ( int nHeap,
int * pnBlocks,
int * pnFreeBytes,
int * pnBiggest )

Report the free blocks of a heap.

The name is inferred.

Parameters
nHeapThe index of the heap.
pnBlocksReceives the number of free blocks.
pnFreeBytesReceives the free bytes.
pnBiggestReceives the bytes of the biggest free block.
Ghidra address:
NTSC-U/C: 0x00299e08
Ghidra address:
PAL: 0x002a3a08

◆ MemRegisterHeap()

int MemRegisterHeap ( const char * pszName,
int * pStart,
int nSizeWords,
int bHandles )

Add a heap to the table.

The name is inferred.

Parameters
pszNameThe name of the heap.
pStartThe region of the heap.
nSizeWordsThe size of the region in words.
bHandlesNon-zero for a heap of handle blocks.
Returns
The index of the heap.
Ghidra address:
NTSC-U/C: 0x00299eb0
Ghidra address:
PAL: 0x002a3ad0

◆ MemSetHeapSize()

void MemSetHeapSize ( int nHeap,
int nSizeWords )

Change the size of a heap.

The name is inferred.

Parameters
nHeapThe index of the heap.
nSizeWordsThe size in words.
Ghidra address:
NTSC-U/C: 0x00299f10
Ghidra address:
PAL: 0x002a3b30

◆ MemPushHeap()

void MemPushHeap ( int nHeap)

Make a heap the one PoolMemAlloc() allocates from, until MemPopHeap().

Make a heap the one allocations come from until the matching MemPopHeap().

The depth of the stack is not checked. The name is inferred.

Parameters
nHeapThe index of the heap.
Ghidra address:
NTSC-U/C: 0x0029a728
Ghidra address:
PAL: 0x002a4348

The name is inferred.

Parameters
nHeapThe table index MemFindHeap() reported.
Ghidra address:
NTSC-U/C: 0x0029a728
Ghidra address:
PAL: 0x002a4348

◆ MemPopHeap()

void MemPopHeap ( )

Undo the latest MemPushHeap().

Return to the heap in use before the last MemPushHeap().

The name is inferred.

Ghidra address:
NTSC-U/C: 0x0029a750
Ghidra address:
PAL: 0x002a4370

◆ MemInit()

void MemInit ( )

Take the memory from the end of the C library's heap to 0x1f70000 as the heap main, and start the memory tracker when it is available.

PoolMemAlloc() calls this before the first allocation. The name is inferred.

Ghidra address:
NTSC-U/C: 0x0029a768
Ghidra address:
PAL: 0x002a4388

◆ MemRealloc()

void * MemRealloc ( void * pBlock,
int nBytes )

Shrink a block in place.

A size of 0 frees the block. A block outside every heap is returned as it is.

Parameters
pBlockThe block, or null.
nBytesThe size in bytes.
Returns
The block, or null after a free.
Ghidra address:
NTSC-U/C: 0x0029aa60
Ghidra address:
PAL: 0x002a4680

◆ MemNumHeaps()

int MemNumHeaps ( )

Report the number of heaps.

Report how many heaps the heap table has.

The name is inferred.

Returns
The number of heaps.
Ghidra address:
NTSC-U/C: 0x0029ae18
Ghidra address:
PAL: 0x002a4a38

The name is inferred.

Returns
The heap count.
Ghidra address:
NTSC-U/C: 0x0029ae18
Ghidra address:
PAL: 0x002a4a38

◆ MemPrintHeap()

void MemPrintHeap ( int nHeap,
PrnStream & stream )

Write each block of a heap.

The name is inferred.

Parameters
nHeapThe index of the heap.
streamThe stream to write to.
Ghidra address:
NTSC-U/C: 0x0029ae30
Ghidra address:
PAL: 0x002a4a50

◆ MemOrPoolAlloc()

void * MemOrPoolAlloc ( int nSize,
const char * pszTag )

Allocate a block of up to 128 bytes from the pool of fixed-size blocks, and a larger block from the pool heaps.

The name is inferred.

Parameters
nSizeThe block size in bytes.
pszTagThe tag to bill the allocation to.
Returns
The block, or null for a size of 0.
Ghidra address:
NTSC-U/C: 0x0029e128
Ghidra address:
PAL: 0x002a7df0

◆ MemOrPoolFree()

void MemOrPoolFree ( int nSize,
void * pBlock )

Return a block MemOrPoolAlloc() handed out.

A null block is ignored. The name is inferred.

Parameters
nSizeThe size MemOrPoolAlloc() was given.
pBlockThe block.
Ghidra address:
NTSC-U/C: 0x0029e170
Ghidra address:
PAL: 0x002a7e38

◆ MemFindHeap()

int MemFindHeap ( const char * pszName)

Look up a heap by its configured name.

The heap table has one 0x18-byte entry per heap, and the lookup compares the name of each entry in table order.

Parameters
pszNameThe heap name, for example "rnd".
Returns
The table index of the heap, or -1 when no heap has that name.
Ghidra address:
NTSC-U/C: 0x0029ad90
Ghidra address:
PAL: 0x002a49b0

◆ MemCompact()

void MemCompact ( int nHeap,
int nByteBudget,
bool bStrictBudget )

Move live blocks of one heap together to merge its free space.

A negative heap index is ignored. With bStrictBudget set, compaction stops before the first block that would take the bytes moved past the budget. Otherwise compaction stops only after the bytes moved exceed the budget, and the last block moved may cross it.

Parameters
nHeapThe table index MemFindHeap() reported.
nByteBudgetThe most bytes to move in this call.
bStrictBudgetWhether the budget is a hard limit.
Ghidra address:
NTSC-U/C: 0x0029af78
Ghidra address:
PAL: 0x002a4b98

◆ PoolMemAlloc()

void * PoolMemAlloc ( int nSize,
const char * pszTag,
int nAlign )

Allocate a block from the pool heaps and bill it to a tag.

Every class-specific operator new forwards here with its class name as the tag, and the global operator new passes the tag new.

Parameters
nSizeThe block size in bytes.
pszTagThe tag to bill the allocation to.
nAlignThe alignment in bytes, a power of two of at least four. Zero selects 16 bytes.
Returns
The block.
Ghidra address:
NTSC-U/C: 0x0029ab68
Ghidra address:
PAL: 0x002a4788

◆ PoolMemFree()

void PoolMemFree ( void * pBlock)

Return a block PoolMemAlloc() handed out to the pool heap that owns it.

A null block is ignored.

Parameters
pBlockThe block.
Ghidra address:
NTSC-U/C: 0x0029acd0
Ghidra address:
PAL: 0x002a48f0

◆ MemConfigureHeaps()

void MemConfigureHeaps ( )

Set the heaps up from the system configuration.

The name is inferred.

Ghidra address:
NTSC-U/C: 0x0029a820
Ghidra address:
PAL: 0x002a4440

◆ MemTerminate()

void MemTerminate ( )

Shut the heaps down.

The body does nothing. The name is inferred.

Ghidra address:
NTSC-U/C: 0x0029aa58
Ghidra address:
PAL: 0x002a4678

◆ MemPoll()

void MemPoll ( )

Record the state of every tracked heap, once per frame.

The name is inferred.

Ghidra address:
NTSC-U/C: 0x0029c6c8
Ghidra address:
PAL: 0x002a62f0

Variable Documentation

◆ g_nMemTrackingEnabled

int g_nMemTrackingEnabled
extern

Non-zero while the memory tracker records allocations.

Ghidra address:
NTSC-U/C: 0x003b23b4
Ghidra address:
PAL: 0x00431274

◆ g_nTrackStl

int g_nTrackStl
extern

Non-zero when the memory tracker bills STL allocations to their container, from track_stl.

Ghidra address:
NTSC-U/C: 0x003b23b8
Ghidra address:
PAL: 0x00431278