NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
mHeap Namespace Reference

Description

Provides high-level heap management utilities built on top of the EGG heap system.

The mHeap namespace wraps and extends the functionality of the EGG heap framework, providing helper functions for creating and managing different heap types used by the game.

It supports:

  • Expandable heaps.
  • Frame heaps.
  • Unit heaps.

It also manages various game-specific heaps:

Enumerations

enum  AllocOptBit_t {
  OPT_NONE = 0 ,
  OPT_CLEAR_ALLOC = BIT_FLAG(0) ,
  OPT_DEBUG_FILL = BIT_FLAG(1) ,
  OPT_THREAD_SAFE = BIT_FLAG(2)
}
 Bit flags controlling heap allocation behavior. These flags are translated into internal MEM heap flags via GetOptFlag(). More...
enum  GAME_HEAP_e {
  GAME_HEAP_DEFAULT ,
  GAME_HEAP_MEM1 ,
  GAME_HEAP_MEM2 ,
  GAME_HEAP_COUNT
}
 The identifiers for the predefined game heaps. More...

Functions

u16 GetOptFlag (AllocOptBit_t opt)
 Converts the allocation option bits to internal MEM heap flags.
EGG::Heap * setCurrentHeap (EGG::Heap *heap)
 Sets the specified heap as the current heap.
void saveCurrentHeap ()
 Saves the currently active heap. The saved heap can later be restored using restoreCurrentHeap().
void restoreCurrentHeap ()
 Restores the previously saved heap as current.
size_t expHeapCost (size_t size, ulong align)
 Calculates the total required size for an expandable heap, including internal overhead.
size_t frmHeapCost (size_t size, ulong align)
 Calculates the total required size for a frame heap, including internal overhead.
size_t untHeapCost (size_t size, ulong count, ulong align)
 Calculates the total required size for an unit heap, including internal overhead.
void destroyFrmHeap (EGG::FrmHeap *heap)
 Destroys a frame heap.
size_t adjustFrmHeap (EGG::FrmHeap *heap)
 Adjusts a frame heap to release unused memory.
EGG::ExpHeap * createExpHeap (size_t size, EGG::Heap *parent, const char *name, ulong align, AllocOptBit_t opt)
 Creates an expandable heap.
EGG::FrmHeap * createFrmHeapToCurrent (size_t size, EGG::Heap *parent, const char *name, ulong align, AllocOptBit_t opt)
 Creates a frame heap and sets it as current.
EGG::FrmHeap * createFrmHeap (size_t size, EGG::Heap *parent, const char *name, ulong align, AllocOptBit_t opt)
 Creates a frame heap.
EGG::UnitHeap * createUntHeap (size_t size, ulong count, EGG::Heap *parent, const char *name, ulong align, AllocOptBit_t opt)
 Creates a unit heap.
bool isValidGameHeapId (u32 idx)
EGG::Heap * createHeap (size_t size, EGG::Heap *parent, const char *name)
 Creates a generic expandable heap, with fast allocation mode and thread-safe de/allocation.
EGG::Heap * createGameHeap (int idx, size_t size, EGG::Heap *parent)
 Creates a game heap.
EGG::Heap * createGameHeap1 (size_t size, EGG::Heap *parent)
 Creates the MEM1 game heap. See createGameHeap().
EGG::Heap * createGameHeap2 (size_t size, EGG::Heap *parent)
 Creates the MEM2 game heap. See createGameHeap().
EGG::Heap * createArchiveHeap (size_t size, EGG::Heap *parent)
 Creates the archive heap. See createHeap().
EGG::Heap * createCommandHeap (size_t size, EGG::Heap *parent)
 Creates the DVD command heap. See createHeap().
EGG::Heap * createDylinkHeap (size_t size, EGG::Heap *parent)
 Creates the REL linking heap. See createHeap().
EGG::Heap * createAssertHeap (EGG::Heap *parent)
 Creates the assert heap.

Variables

u8 g_DefaultGameHeapId = GAME_HEAP_MEM1
 The default game heap to be used if one isn't specified.
const char *const s_GameHeapNames [GAME_HEAP_COUNT]
 The game heap names.
EGG::Heap * s_SavedCurrentHeap
 The saved current heap.
EGG::Heap * g_gameHeaps [GAME_HEAP_COUNT]
 The game heaps.
EGG::Heap * g_archiveHeap
 The archive resource heap.
EGG::Heap * g_commandHeap
 The DVD command heap.
EGG::Heap * g_dylinkHeap
 The REL linking heap.
EGG::Heap * g_assertHeap
 The assert heap.

Enumeration Type Documentation

◆ AllocOptBit_t

Bit flags controlling heap allocation behavior. These flags are translated into internal MEM heap flags via GetOptFlag().

Enumerator
OPT_NONE 

No special allocation options.

OPT_CLEAR_ALLOC 

Memory blocks are cleared upon allocation.

OPT_DEBUG_FILL 

Memory blocks are filled with different values depending on the heap status.

OPT_THREAD_SAFE 

Enables thread-safe memory block de/allocation.

Definition at line 28 of file m_heap.hpp.

◆ GAME_HEAP_e

The identifiers for the predefined game heaps.

Enumerator
GAME_HEAP_DEFAULT 

The default game heap (alias of MEM1 or MEM2).

GAME_HEAP_MEM1 

The game heap allocated in MEM1.

GAME_HEAP_MEM2 

The game heap allocated in MEM2.

GAME_HEAP_COUNT 

The total number of game heaps.

Definition at line 37 of file m_heap.hpp.

Function Documentation

◆ GetOptFlag()

u16 mHeap::GetOptFlag ( AllocOptBit_t opt)

Converts the allocation option bits to internal MEM heap flags.

Parameters
optThe allocation option bits.
Returns
The corresponding MEM heap flag mask.

Definition at line 19 of file m_heap.cpp.

◆ setCurrentHeap()

EGG::Heap * mHeap::setCurrentHeap ( EGG::Heap * heap)

Sets the specified heap as the current heap.

Parameters
heapThe heap to become current.
Returns
The previously current heap.

Definition at line 37 of file m_heap.cpp.

◆ saveCurrentHeap()

void mHeap::saveCurrentHeap ( )

Saves the currently active heap. The saved heap can later be restored using restoreCurrentHeap().

Definition at line 172 of file m_heap.cpp.

◆ restoreCurrentHeap()

void mHeap::restoreCurrentHeap ( )

Restores the previously saved heap as current.

Definition at line 176 of file m_heap.cpp.

◆ expHeapCost()

size_t mHeap::expHeapCost ( size_t size,
ulong align )

Calculates the total required size for an expandable heap, including internal overhead.

Parameters
sizeThe requested usable size.
alignThe lignment requirement.
Returns
The total allocation size required.

Definition at line 71 of file m_heap.cpp.

◆ frmHeapCost()

size_t mHeap::frmHeapCost ( size_t size,
ulong align )

Calculates the total required size for a frame heap, including internal overhead.

Parameters
sizeThe requested usable size.
alignThe lignment requirement.
Returns
The total allocation size required.

Definition at line 125 of file m_heap.cpp.

◆ untHeapCost()

size_t mHeap::untHeapCost ( size_t size,
ulong count,
ulong align )

Calculates the total required size for an unit heap, including internal overhead.

Parameters
sizeThe requested usable size.
countThe number of units.
alignThe lignment requirement.
Returns
The total allocation size required.

Definition at line 154 of file m_heap.cpp.

◆ destroyFrmHeap()

void mHeap::destroyFrmHeap ( EGG::FrmHeap * heap)

Destroys a frame heap.

Parameters
heapThe frame heap to destroy, or nullptr .

Definition at line 105 of file m_heap.cpp.

◆ adjustFrmHeap()

size_t mHeap::adjustFrmHeap ( EGG::FrmHeap * heap)

Adjusts a frame heap to release unused memory.

Parameters
heapThe frame heap to adjust, or nullptr .
Returns
The total available space in the heap, or 0 if the adjust operation failed.

Definition at line 111 of file m_heap.cpp.

◆ createExpHeap()

EGG::ExpHeap * mHeap::createExpHeap ( size_t size,
EGG::Heap * parent,
const char * name,
ulong align,
AllocOptBit_t opt )

Creates an expandable heap.

Parameters
sizeThe size of the heap, or -1 to use all space available.
parentThe parent heap.
nameThe heap name, or nullptr .
alignThe heap alignment (minimum 0x20).
optThe allocation options.
Returns
A pointer to the created heap, or nullptr on failure.

Definition at line 41 of file m_heap.cpp.

◆ createFrmHeapToCurrent()

EGG::FrmHeap * mHeap::createFrmHeapToCurrent ( size_t size,
EGG::Heap * parent,
const char * name,
ulong align,
AllocOptBit_t opt )

Creates a frame heap and sets it as current.

Parameters
sizeThe size of the heap, or -1 to use all space available.
parentThe parent heap.
nameThe heap name, or nullptr .
alignThe heap alignment (minimum 0x20).
optThe allocation options.
Returns
A pointer to the created heap, or nullptr on failure.

Definition at line 181 of file m_heap.cpp.

◆ createFrmHeap()

EGG::FrmHeap * mHeap::createFrmHeap ( size_t size,
EGG::Heap * parent,
const char * name,
ulong align,
AllocOptBit_t opt )

Creates a frame heap.

Parameters
sizeThe size of the heap, or -1 to use all space available.
parentThe parent heap.
nameThe heap name, or nullptr .
alignThe heap alignment (minimum 0x20).
optThe allocation options.
Returns
A pointer to the created heap, or nullptr on failure.

Definition at line 75 of file m_heap.cpp.

◆ createUntHeap()

EGG::UnitHeap * mHeap::createUntHeap ( size_t size,
ulong count,
EGG::Heap * parent,
const char * name,
ulong align,
AllocOptBit_t opt )

Creates a unit heap.

Parameters
sizeThe size of the heap, or -1 to use all space available.
countThe number of units.
parentThe parent heap.
nameThe heap name, or nullptr .
alignThe heap alignment (minimum 0x20).
optThe allocation options.
Returns
A pointer to the created heap, or nullptr on failure.

Definition at line 129 of file m_heap.cpp.

◆ isValidGameHeapId()

bool mHeap::isValidGameHeapId ( u32 idx)
inline

Definition at line 134 of file m_heap.hpp.

◆ createHeap()

EGG::Heap * mHeap::createHeap ( size_t size,
EGG::Heap * parent,
const char * name )

Creates a generic expandable heap, with fast allocation mode and thread-safe de/allocation.

Parameters
sizeThe heap size.
parentThe parent heap.
nameThe heap name, or nullptr .
Returns
A pointer to the created heap, or nullptr on failure.

Definition at line 158 of file m_heap.cpp.

◆ createGameHeap()

EGG::Heap * mHeap::createGameHeap ( int idx,
size_t size,
EGG::Heap * parent )

Creates a game heap.

Parameters
idxThe game heap index.
sizeThe heap size.
parentThe parent heap.
Returns
A pointer to the created heap, or nullptr if invalid index.

Definition at line 190 of file m_heap.cpp.

◆ createGameHeap1()

EGG::Heap * mHeap::createGameHeap1 ( size_t size,
EGG::Heap * parent )

Creates the MEM1 game heap. See createGameHeap().

Definition at line 203 of file m_heap.cpp.

◆ createGameHeap2()

EGG::Heap * mHeap::createGameHeap2 ( size_t size,
EGG::Heap * parent )

Creates the MEM2 game heap. See createGameHeap().

Definition at line 207 of file m_heap.cpp.

◆ createArchiveHeap()

EGG::Heap * mHeap::createArchiveHeap ( size_t size,
EGG::Heap * parent )

Creates the archive heap. See createHeap().

Definition at line 211 of file m_heap.cpp.

◆ createCommandHeap()

EGG::Heap * mHeap::createCommandHeap ( size_t size,
EGG::Heap * parent )

Creates the DVD command heap. See createHeap().

Definition at line 216 of file m_heap.cpp.

◆ createDylinkHeap()

EGG::Heap * mHeap::createDylinkHeap ( size_t size,
EGG::Heap * parent )

Creates the REL linking heap. See createHeap().

Definition at line 221 of file m_heap.cpp.

◆ createAssertHeap()

EGG::Heap * mHeap::createAssertHeap ( EGG::Heap * parent)

Creates the assert heap.

The size is determined automatically using EGG::AssertHeap::getMinSizeForCreate().

Definition at line 226 of file m_heap.cpp.

Variable Documentation

◆ g_DefaultGameHeapId

u8 mHeap::g_DefaultGameHeapId = GAME_HEAP_MEM1
extern

The default game heap to be used if one isn't specified.

Definition at line 4 of file m_heap.cpp.

◆ s_GameHeapNames

const char *const mHeap::s_GameHeapNames
extern
Initial value:
= {
nullptr,
GAME_HEAP_1_NAME,
GAME_HEAP_2_NAME,
}

The game heap names.

Definition at line 5 of file m_heap.cpp.

◆ s_SavedCurrentHeap

EGG::Heap * mHeap::s_SavedCurrentHeap
extern

The saved current heap.

Definition at line 11 of file m_heap.cpp.

◆ g_gameHeaps

EGG::Heap * mHeap::g_gameHeaps
extern

The game heaps.

Definition at line 13 of file m_heap.cpp.

◆ g_archiveHeap

EGG::Heap * mHeap::g_archiveHeap
extern

The archive resource heap.

Definition at line 14 of file m_heap.cpp.

◆ g_commandHeap

EGG::Heap * mHeap::g_commandHeap
extern

The DVD command heap.

Definition at line 15 of file m_heap.cpp.

◆ g_dylinkHeap

EGG::Heap * mHeap::g_dylinkHeap
extern

The REL linking heap.

Definition at line 16 of file m_heap.cpp.

◆ g_assertHeap

EGG::Heap * mHeap::g_assertHeap
extern

The assert heap.

Definition at line 17 of file m_heap.cpp.