NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
mem_expHeap.h
1#ifndef RVL_SDK_MEM_EXP_HEAP_H
2#define RVL_SDK_MEM_EXP_HEAP_H
3#include <types.h>
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#define MEM_EXP_HEAP_MIN_SIZE \
9 (sizeof(MEMiHeapHead) + sizeof(MEMiExpHeapHead) + \
10 sizeof(MEMiExpHeapMBlock) + 4)
11
12// Forward declarations
13typedef struct MEMiHeapHead MEMiHeapHead;
14
15typedef enum {
16 MEM_EXP_HEAP_ALLOC_FAST, //!< When allocating memory blocks, take the first
17 //!< usable found block rather than trying to
18 //!< find a more optimal block
19} MEMiExpHeapAllocMode;
20
21typedef struct MEMiExpHeapMBlock {
22 u16 state; // at 0x0
23 union {
24 u16 settings;
25 struct {
26 u16 allocDir : 1;
27 u16 align : 7;
28 u16 group : 8;
29 };
30 }; // at 0x2
31 u32 size; // at 0x4
32 struct MEMiExpHeapMBlock* prev; // at 0x8
33 struct MEMiExpHeapMBlock* next; // at 0xC
35
36typedef struct MEMiExpHeapMBlockList {
37 MEMiExpHeapMBlock* head; // at 0x0
38 MEMiExpHeapMBlock* tail; // at 0x4
40
41// Placed in heap after base heap head
42typedef struct MEMiExpHeapHead {
43 MEMiExpHeapMBlockList freeMBlocks; // at 0x0
44 MEMiExpHeapMBlockList usedMBlocks; // at 0x8
45 u16 group; // at 0x10
46 union {
47 u16 SHORT_0x12;
48 struct {
49 u16 SHORT_0x12_0_15 : 15;
50 u16 allocMode : 1;
51 };
52 }; // at 0x12
54
55MEMiHeapHead* MEMCreateExpHeapEx(void* start, u32 size, u16 opt);
56MEMiHeapHead* MEMDestroyExpHeap(MEMiHeapHead* heap);
57void* MEMAllocFromExpHeapEx(MEMiHeapHead* heap, u32 size, s32 align);
58u32 MEMResizeForMBlockExpHeap(MEMiHeapHead* heap, void* memBlock, u32 size);
59void MEMFreeToExpHeap(MEMiHeapHead* heap, void* memBlock);
60u32 MEMGetAllocatableSizeForExpHeapEx(MEMiHeapHead* heap, s32 align);
61u32 MEMAdjustExpHeap(MEMiHeapHead* heap);
62
63static MEMiHeapHead* MEMCreateExpHeap(void* start, u32 size) {
64 return MEMCreateExpHeapEx(start, size, 0);
65}
66
67static void* MEMAllocFromExpHeap(MEMiHeapHead* heap, u32 size) {
68 return MEMAllocFromExpHeapEx(heap, size, 4);
69}
70
71static u32 MEMGetAllocatableSizeForExpHeap(MEMiHeapHead* heap) {
72 return MEMGetAllocatableSizeForExpHeapEx(heap, 4);
73}
74
75#ifdef __cplusplus
76}
77#endif
78#endif