1#include <game/mLib/m_allocator_dummy_heap.hpp>
2#include <game/mLib/m_allocator.hpp>
3#include <game/mLib/m_heap.hpp>
4#include <lib/egg/core/eggFrmHeap.h>
8void *mAllocatorDummyHeap_c::AllocatorAllocForDummyHeap(MEMAllocator *,
size_t) {
return nullptr; }
9void mAllocatorDummyHeap_c::AllocatorFreeForDummyHeap(MEMAllocator *,
void *) {}
11mAllocatorDummyHeap_c::mAllocatorDummyHeap_c() {
15mAllocatorDummyHeap_c::~mAllocatorDummyHeap_c() {}
17int mAllocatorDummyHeap_c::getHeapKind()
const {
21void mAllocatorDummyHeap_c::initAllocator(EGG::Allocator *allocator,
long alignment) {
22 const static MEMAllocatorFuncs sAllocatorFunc = {
23 AllocatorAllocForDummyHeap,
24 AllocatorFreeForDummyHeap
26 allocator->funcs = &sAllocatorFunc;
27 allocator->heap = mHeapHandle;
28 allocator->heapParam1 = alignment;
29 allocator->heapParam2 = 0;
32void *mAllocatorDummyHeap_c::alloc(
size_t bytes,
long alignment) {
36void mAllocatorDummyHeap_c::free(
void *ptr) {}
38void mAllocatorDummyHeap_c::destroy() {}
40size_t mAllocatorDummyHeap_c::resizeForMBlock(
void *ptr,
size_t newSize) {
44u32 mAllocatorDummyHeap_c::getTotalFreeSize() {
48size_t mAllocatorDummyHeap_c::getAllocatableSize(
long alignment) {
52size_t mAllocatorDummyHeap_c::adjust() {
65bool mAllocator_c::attach(EGG::Heap *heap,
int alignment) {
66 if (heap ==
nullptr) {
67 heap = EGG::Heap::sCurrentHeap;
71 heap->initAllocator(
this, alignment);
75void *mAllocator_c::alloc(
size_t size) {
76 return EGG::Allocator::alloc(size);
79void mAllocator_c::free(
void *ptr) {
80 EGG::Allocator::free(ptr);
83void mAllocator_c::init(EGG::Heap *heap) {
84 new(heap, 4) mAllocatorDummyHeap_c();
93bool mHeapAllocator_c::createFrmHeap(
size_t size, EGG::Heap *parent,
const char *name, ulong align,
mHeap::AllocOptBit_t opt) {
96 if (heap ==
nullptr) {
105 EGG::Heap *dummyHeap = mAllocatorDummyHeap_c::getInstance();
106 if (mpHeap != dummyHeap) {
112size_t mHeapAllocator_c::adjustFrmHeap() {
113 EGG::Heap *dummyHeap = mAllocatorDummyHeap_c::getInstance();
114 if (mpHeap == dummyHeap) {
118 EGG::FrmHeap *heap = EGG::Heap::dynamicCastToFrm(mpHeap);
122bool mHeapAllocator_c::createFrmHeapToCurrent(
size_t size, EGG::Heap *parent,
const char *name, ulong align,
mHeap::AllocOptBit_t opt) {
123 if (!createFrmHeap(size, parent, name, align, opt)) {
132size_t mHeapAllocator_c::adjustFrmHeapRestoreCurrent() {
134 EGG::FrmHeap *heap = EGG::Heap::dynamicCastToFrm(mpHeap);
A non-functional heap to be used when mHeapAllocator_c does not have a proper heap.
mAllocator_c()
Constructs a new allocator.
virtual ~mAllocator_c()
Destroys the allocator.
void destroyHeap()
Destroys the underlying heap and replaces it with the dummy heap.
virtual ~mHeapAllocator_c()
Destroys the heap allocator.
mHeapAllocator_c()
Constructs a new heap allocator.
EGG::FrmHeap * createFrmHeap(size_t size, EGG::Heap *parent, const char *name, ulong align, AllocOptBit_t opt)
Creates a frame heap.
void saveCurrentHeap()
Saves the currently active heap. The saved heap can later be restored using restoreCurrentHeap().
size_t adjustFrmHeap(EGG::FrmHeap *heap)
Adjusts a frame heap to release unused memory.
void restoreCurrentHeap()
Restores the previously saved heap as current.
AllocOptBit_t
Bit flags controlling heap allocation behavior. These flags are translated into internal MEM heap fla...
EGG::Heap * setCurrentHeap(EGG::Heap *heap)
Sets the specified heap as the current heap.