A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
Kinoko::Abstract::Memory::MEMiExpHeapHead Class Reference

#include <ExpHeap.hh>

Description

Low-level implementation of a memory heap for managing dynamic memory allocation. Allocation may occur anywhere within the memory space the heap is created from.

Due to requesting chunks from a provided memory block, internal fragmentation is non-existent, but external fragmentation is still possible. Allocating temporary blocks from the tail, and scene-permanent blocks from the head, is recommended. The memory overhead per allocation is sizeof(MEMiExpBlockHead).

Definition at line 72 of file ExpHeap.hh.

Inheritance diagram for Kinoko::Abstract::Memory::MEMiExpHeapHead:

Public Types

typedef std::function< void(void *, MEMiHeapHead *, uintptr_t)> Visitor
Public Types inherited from Kinoko::Abstract::Memory::MEMiHeapHead
enum class  FillType {
  NoUse = 0 ,
  Alloc = 1 ,
  Free = 2
}
enum class  eOptFlag {
  ZeroFillAlloc = 0 ,
  DebugFillAlloc = 1
}
typedef EGG::TBitFlag< u16, eOptFlag > OptFlag

Public Member Functions

void destroy ()
void * alloc (size_t size, s32 align)
void free (void *block)
u32 getAllocatableSize (s32 align) const
void visitAllocated (Visitor visitor, uintptr_t param)
u16 getGroupID () const
void setGroupID (u16 groupID)
void * calcUsedEnd ()
 Helper function which finds the end of the used heap region (including the tail head).
Public Member Functions inherited from Kinoko::Abstract::Memory::MEMiHeapHead
MEMList & getChildList ()
void * getHeapStart ()
void * getHeapEnd ()

Static Public Member Functions

static MEMiExpHeapHead * create (void *startAddress, size_t size, u16 flag)
Static Public Member Functions inherited from Kinoko::Abstract::Memory::MEMiHeapHead
static MEMList & getRootList ()
static u32 getFillVal (FillType type)
static MEMiHeapHead * findContainHeap (const void *block)
static constexpr u16 getLinkOffset ()

Private Types

enum class  eAttribute { BestFitAlloc = 0 }
typedef EGG::TBitFlag< u16, eAttribute > Attribute

Private Member Functions

 MEMiExpHeapHead (void *end, u16 opt)
void * allocFromHead (size_t size, s32 alignment)
void * allocFromTail (size_t size, s32 alignment)
void * allocUsedBlockFromFreeBlock (MEMiExpBlockHead *block, void *address, u32 size, s32 direction)
bool recycleRegion (const Region &initialRegion)

Private Attributes

MEMiExpBlockList m_freeBlocks
MEMiExpBlockList m_usedBlocks
u16 m_groupId
Attribute m_attribute

Static Private Attributes

static constexpr u32 EXP_HEAP_SIGNATURE = 0x45585048

Additional Inherited Members

Protected Member Functions inherited from Kinoko::Abstract::Memory::MEMiHeapHead
 MEMiHeapHead (u32 signature, void *heapStart, void *heapEnd, const OptFlag &opt)
void fillNoUseMemory (void *address, u32 size)
void fillAllocMemory (void *address, u32 size)
void fillFreeMemory (void *address, u32 size)

Member Typedef Documentation

◆ Attribute

typedef EGG::TBitFlag<u16, eAttribute> Kinoko::Abstract::Memory::MEMiExpHeapHead::Attribute
private

Definition at line 97 of file ExpHeap.hh.

◆ Visitor

typedef std::function<void(void *, MEMiHeapHead *, uintptr_t)> Kinoko::Abstract::Memory::MEMiExpHeapHead::Visitor

Definition at line 78 of file ExpHeap.hh.

Member Enumeration Documentation

◆ eAttribute

enum class Kinoko::Abstract::Memory::MEMiExpHeapHead::eAttribute
strongprivate

Definition at line 94 of file ExpHeap.hh.

Constructor & Destructor Documentation

◆ MEMiExpHeapHead()

Kinoko::Abstract::Memory::MEMiExpHeapHead::MEMiExpHeapHead ( void * end,
u16 opt )
private

Definition at line 91 of file ExpHeap.cc.

◆ ~MEMiExpHeapHead()

Kinoko::Abstract::Memory::MEMiExpHeapHead::~MEMiExpHeapHead ( )
privatedefault0x80198D58

Member Function Documentation

◆ alloc()

void * Kinoko::Abstract::Memory::MEMiExpHeapHead::alloc ( size_t size,
s32 align )
0x80198D88

Definition at line 137 of file ExpHeap.cc.

◆ allocFromHead()

void * Kinoko::Abstract::Memory::MEMiExpHeapHead::allocFromHead ( size_t size,
s32 alignment )
nodiscardprivate0x8019899C

Definition at line 228 of file ExpHeap.cc.

◆ allocFromTail()

void * Kinoko::Abstract::Memory::MEMiExpHeapHead::allocFromTail ( size_t size,
s32 alignment )
nodiscardprivate0x80198A78

Definition at line 264 of file ExpHeap.cc.

◆ allocUsedBlockFromFreeBlock()

void * Kinoko::Abstract::Memory::MEMiExpHeapHead::allocUsedBlockFromFreeBlock ( MEMiExpBlockHead * block,
void * address,
u32 size,
s32 direction )
nodiscardprivate0x80198798

Definition at line 300 of file ExpHeap.cc.

◆ calcUsedEnd()

void * Kinoko::Abstract::Memory::MEMiExpHeapHead::calcUsedEnd ( )

Helper function which finds the end of the used heap region (including the tail head).

Returns
Pointer to the end of the used heap region (including the tail head)

This is used by Host::Context to discern the minimum memcpy size required to preserve the entire state of the heap. Falls back to getHeapHead() if the tail block is not found.

Definition at line 218 of file ExpHeap.cc.

◆ create()

MEMiExpHeapHead * Kinoko::Abstract::Memory::MEMiExpHeapHead::create ( void * startAddress,
size_t size,
u16 flag )
static0x80198CA8

Definition at line 112 of file ExpHeap.cc.

◆ destroy()

void Kinoko::Abstract::Memory::MEMiExpHeapHead::destroy ( )

Definition at line 132 of file ExpHeap.cc.

◆ free()

void Kinoko::Abstract::Memory::MEMiExpHeapHead::free ( void * block)
0x80199038

Definition at line 154 of file ExpHeap.cc.

◆ getAllocatableSize()

u32 Kinoko::Abstract::Memory::MEMiExpHeapHead::getAllocatableSize ( s32 align) const
nodiscard0x80199180

Definition at line 168 of file ExpHeap.cc.

◆ getGroupID()

u16 Kinoko::Abstract::Memory::MEMiExpHeapHead::getGroupID ( ) const
nodiscard0x8019934C

Definition at line 204 of file ExpHeap.cc.

◆ recycleRegion()

bool Kinoko::Abstract::Memory::MEMiExpHeapHead::recycleRegion ( const Region & initialRegion)
private

Definition at line 344 of file ExpHeap.cc.

◆ setGroupID()

void Kinoko::Abstract::Memory::MEMiExpHeapHead::setGroupID ( u16 groupID)
0x80199258

Definition at line 209 of file ExpHeap.cc.

◆ visitAllocated()

void Kinoko::Abstract::Memory::MEMiExpHeapHead::visitAllocated ( Visitor visitor,
uintptr_t param )
0x801992A8

Definition at line 195 of file ExpHeap.cc.

Member Data Documentation

◆ EXP_HEAP_SIGNATURE

u32 Kinoko::Abstract::Memory::MEMiExpHeapHead::EXP_HEAP_SIGNATURE = 0x45585048
staticconstexprprivate

Definition at line 113 of file ExpHeap.hh.

◆ m_attribute

Attribute Kinoko::Abstract::Memory::MEMiExpHeapHead::m_attribute
private

Definition at line 111 of file ExpHeap.hh.

◆ m_freeBlocks

MEMiExpBlockList Kinoko::Abstract::Memory::MEMiExpHeapHead::m_freeBlocks
private

Definition at line 105 of file ExpHeap.hh.

◆ m_groupId

u16 Kinoko::Abstract::Memory::MEMiExpHeapHead::m_groupId
private

Definition at line 107 of file ExpHeap.hh.

◆ m_usedBlocks

MEMiExpBlockList Kinoko::Abstract::Memory::MEMiExpHeapHead::m_usedBlocks
private

Definition at line 106 of file ExpHeap.hh.