Kinoko
A reimplementation of Mario Kart Wii's physics engine in C++
Toggle main menu visibility
Loading...
Searching...
No Matches
ExpHeap.hh
1
#pragma once
2
3
#include "abstract/memory/HeapCommon.hh"
4
5
#include <functional>
6
7
namespace
Kinoko::Abstract::Memory {
8
10
struct
Region {
11
Region(
void
*start,
void
*end);
12
[[nodiscard]] uintptr_t getRange()
const
;
13
14
void
*start;
15
void
*end;
16
};
17
18
struct
MEMiExpBlockHead
;
19
21
struct
MEMiExpBlockLink
{
22
MEMiExpBlockHead
*m_prev;
23
MEMiExpBlockHead
*m_next;
24
};
25
27
struct
MEMiExpBlockList
{
28
MEMiExpBlockHead
*insert(
MEMiExpBlockHead
*block,
MEMiExpBlockHead
*prev);
29
MEMiExpBlockHead
*append(
MEMiExpBlockHead
*block);
30
MEMiExpBlockHead
*remove(
MEMiExpBlockHead
*block);
31
32
MEMiExpBlockHead
*m_head;
33
MEMiExpBlockHead
*m_tail;
34
};
35
38
struct
MEMiExpBlockHead {
39
private
:
40
MEMiExpBlockHead(
const
Region
®ion, u16 signature);
41
42
public
:
43
[[nodiscard]]
static
MEMiExpBlockHead *createFree(
const
Region
®ion);
44
[[nodiscard]]
static
MEMiExpBlockHead *createUsed(
const
Region
®ion);
45
46
[[nodiscard]]
Region
getRegion()
const
;
47
[[nodiscard]]
void
*getMemoryStart()
const
;
48
[[nodiscard]]
void
*getMemoryEnd()
const
;
49
50
u16 m_signature;
51
union
{
52
u16 val;
53
struct
{
54
u16 direction : 1;
55
u16 alignment : 7;
56
u16 groupId : 8;
57
} fields;
58
} m_attribute;
59
u32 m_size;
60
#ifdef BUILD_DEBUG
61
u32 m_tag;
62
#endif
// BUILD_DEBUG
63
MEMiExpBlockLink
m_link;
64
};
65
72
class
MEMiExpHeapHead :
public
MEMiHeapHead {
73
private
:
74
MEMiExpHeapHead(
void
*end, u16 opt);
75
~MEMiExpHeapHead();
76
77
public
:
78
typedef
std::function<void(
void
*, MEMiHeapHead *, uintptr_t)> Visitor;
79
80
static
MEMiExpHeapHead *create(
void
*startAddress,
size_t
size, u16 flag);
81
void
destroy();
82
83
void
*alloc(
size_t
size, s32 align);
84
void
free(
void
*block);
85
[[nodiscard]] u32 getAllocatableSize(s32 align)
const
;
86
void
visitAllocated(Visitor visitor, uintptr_t param);
87
88
[[nodiscard]] u16 getGroupID()
const
;
89
void
setGroupID(u16 groupID);
90
91
private
:
92
enum class
eAttribute {
93
BestFitAlloc = 0,
94
};
95
typedef
EGG::TBitFlag<u16, eAttribute>
Attribute;
96
97
[[nodiscard]]
void
*allocFromHead(
size_t
size, s32 alignment);
98
[[nodiscard]]
void
*allocFromTail(
size_t
size, s32 alignment);
99
[[nodiscard]]
void
*allocUsedBlockFromFreeBlock(
MEMiExpBlockHead
*block,
void
*address,
100
u32 size, s32 direction);
101
bool
recycleRegion(
const
Region
&initialRegion);
102
103
MEMiExpBlockList
m_freeBlocks;
104
MEMiExpBlockList
m_usedBlocks;
105
u16 m_groupId;
106
#ifdef BUILD_DEBUG
107
u32 m_tag;
108
#endif
// BUILD_DEBUG
109
Attribute m_attribute;
110
111
static
constexpr
u32 EXP_HEAP_SIGNATURE = 0x45585048;
// EXPH
112
};
113
114
}
// namespace Kinoko::Abstract::Memory
Kinoko::Abstract::Memory::MEMiExpBlockHead
Head of the memory block. Contains information about the block and a link in the corresponding used/f...
Definition
ExpHeap.hh:38
Kinoko::Abstract::Memory::MEMiExpBlockLink
Link of a non-intrusive doubly-linked list.
Definition
ExpHeap.hh:21
Kinoko::Abstract::Memory::MEMiExpBlockList
Non-intrusive doubly-linked list.
Definition
ExpHeap.hh:27
Kinoko::Abstract::Memory::Region
Represents a region of memory.
Definition
ExpHeap.hh:10
Kinoko::EGG::TBitFlag
Wrapper around an integral type with an enum corresponding to its bits.
Definition
BitFlag.hh:23
abstract
memory
ExpHeap.hh
Made by
Malleo
. Logo by
vabold
. Website generated by
Doxygen
1.17.0