A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
HeapCommon.hh
1#pragma once
2
3#include "abstract/memory/List.hh"
4
5#include <egg/core/BitFlag.hh>
6
7#include <array>
8
9namespace Host {
10
11class Context;
12
13} // namespace Host
14
15namespace Abstract::Memory {
16
20 friend class Host::Context;
21
22public:
23 enum class FillType {
24 NoUse = 0,
25 Alloc = 1,
26 Free = 2,
27 };
28
29 enum class eOptFlag {
30 ZeroFillAlloc = 0,
31 DebugFillAlloc = 1,
32 };
34
35 [[nodiscard]] MEMList &getChildList();
36 [[nodiscard]] void *getHeapStart();
37 [[nodiscard]] void *getHeapEnd();
38
39 [[nodiscard]] static MEMList &getRootList();
40 [[nodiscard]] static u32 getFillVal(FillType type);
41 [[nodiscard]] static MEMiHeapHead *findContainHeap(const void *block);
42
43 [[nodiscard]] static constexpr u16 getLinkOffset() {
44 return offsetof(MEMiHeapHead, m_link);
45 }
46
47protected:
48 MEMiHeapHead(u32 signature, void *heapStart, void *heapEnd, const OptFlag &opt);
50
51 void fillNoUseMemory(void *address, u32 size);
52 void fillAllocMemory(void *address, u32 size);
53 void fillFreeMemory(void *address, u32 size);
54
55private:
56 [[nodiscard]] static MEMiHeapHead *findContainHeap(MEMList *list, const void *block);
57 [[nodiscard]] MEMList &findListContainHeap() const;
58
59 u32 m_signature;
60 OptFlag m_optFlag;
61 MEMLink m_link;
62 MEMList m_childList;
63 void *m_heapStart;
64 void *m_heapEnd;
65
66 static MEMList s_rootList;
67 static constexpr std::array<u32, 3> s_fillVals = {{
68 0xC3C3C3C3,
69 0xF3F3F3F3,
70 0xD3D3D3D3,
71 }};
72};
73
74} // namespace Abstract::Memory
A low-level representation of a memory heap for managing dynamic memory allocation....
Definition HeapCommon.hh:19
Contexts can be used to restore a previous memory state for the current session.
Definition Context.hh:59
Represents the host application.
Definition HeapCommon.hh:9
Intrusive doubly-linked list. Links are placed within the corresponding object.
Definition List.hh:14
Wrapper around an integral type with an enum corresponding to its bits.
Definition BitFlag.hh:16