1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-14 21:40:03 +00:00
oot/src/code/gamealloc.c

84 lines
2.1 KiB
C
Raw Normal View History

#include "global.h"
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
void GameAlloc_Log(GameAlloc* this) {
2020-03-17 04:31:30 +00:00
GameAllocEntry* iter;
osSyncPrintf("this = %08x\n", this);
iter = this->base.next;
2020-03-22 21:19:43 +00:00
while (iter != &this->base) {
2020-03-17 04:31:30 +00:00
osSyncPrintf("ptr = %08x size = %d\n", iter, iter->size);
iter = iter->next;
}
}
2020-03-22 21:19:43 +00:00
void* GameAlloc_MallocDebug(GameAlloc* this, u32 size, const char* file, s32 line) {
2020-03-17 04:31:30 +00:00
GameAllocEntry* ptr;
2020-03-22 21:19:43 +00:00
ptr = SystemArena_MallocDebug(size + sizeof(GameAllocEntry), file, line);
if (ptr) {
2020-03-17 04:31:30 +00:00
ptr->size = size;
ptr->prev = this->head;
this->head->next = ptr;
this->head = ptr;
ptr->next = &this->base;
this->base.prev = this->head;
return ptr + 1;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
return NULL;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
2020-03-22 21:19:43 +00:00
void* GameAlloc_Malloc(GameAlloc* this, u32 size) {
2020-03-17 04:31:30 +00:00
GameAllocEntry* ptr;
2020-03-22 21:19:43 +00:00
ptr = SystemArena_MallocDebug(size + sizeof(GameAllocEntry), "../gamealloc.c", 93);
if (ptr) {
2020-03-17 04:31:30 +00:00
ptr->size = size;
ptr->prev = this->head;
this->head->next = ptr;
this->head = ptr;
ptr->next = &this->base;
this->base.prev = this->head;
return ptr + 1;
2020-03-22 21:19:43 +00:00
} else {
2020-03-17 04:31:30 +00:00
return NULL;
2020-03-22 21:19:43 +00:00
}
2020-03-17 04:31:30 +00:00
}
2020-03-22 21:19:43 +00:00
void GameAlloc_Free(GameAlloc* this, void* data) {
2020-03-17 04:31:30 +00:00
GameAllocEntry* ptr;
2020-03-22 21:19:43 +00:00
if (data) {
2020-03-17 04:31:30 +00:00
ptr = &((GameAllocEntry*)data)[-1];
LogUtils_CheckNullPointer("ptr->prev", ptr->prev, "../gamealloc.c", 120);
LogUtils_CheckNullPointer("ptr->next", ptr->next, "../gamealloc.c", 121);
ptr->prev->next = ptr->next;
ptr->next->prev = ptr->prev;
this->head = this->base.prev;
SystemArena_FreeDebug(ptr, "../gamealloc.c", 125);
}
}
2020-03-22 21:19:43 +00:00
void GameAlloc_Cleanup(GameAlloc* this) {
2020-03-17 04:31:30 +00:00
GameAllocEntry* next;
GameAllocEntry* cur;
next = this->base.next;
2020-03-22 21:19:43 +00:00
while (&this->base != next) {
2020-03-17 04:31:30 +00:00
cur = next;
next = next->next;
SystemArena_FreeDebug(cur, "../gamealloc.c", 145);
}
this->head = &this->base;
this->base.next = &this->base;
this->base.prev = &this->base;
}
2020-03-22 21:19:43 +00:00
void GameAlloc_Init(GameAlloc* this) {
2020-03-17 04:31:30 +00:00
this->head = &this->base;
this->base.next = &this->base;
this->base.prev = &this->base;
}