Files
mm/src/code/gamealloc.c
T
Anghelo Carvajal c44e26a143 __osMalloc.c OK (#395)
* __osRealloc

* match __osCheckArena

* cleanup

* Import bss, unreferenced strings and cleanup

* format

* Reviews

* Move convert.h to ultra64/

* Make the os_malloc.h header

* potato

* renames and fixes

* format

* small doc pass
}

* format

* minor changes

* Introduce system_malloc.h

* Docs pass

* fix

* format

* stuff

* Apply suggestions from code review

Co-authored-by: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com>

* review

* format

* remove repeated sentence

* Apply suggestions from code review

Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com>

* include headers

* review

* Rename __osMallocAddHeap

* remove @brief

* Update src/boot_O2/__osMalloc.c

Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>

Co-authored-by: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com>
Co-authored-by: Tharo <17233964+Thar0@users.noreply.github.com>
Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>
2022-01-11 23:25:14 +00:00

61 lines
1.4 KiB
C

#include "global.h"
#include "system_malloc.h"
void GameAlloc_Log(GameAlloc* this) {
GameAllocEntry* iter;
iter = this->base.next;
while (iter != &this->base) {
iter = iter->next;
}
}
void* GameAlloc_Malloc(GameAlloc* this, size_t size) {
GameAllocEntry* ptr = SystemArena_Malloc(size + sizeof(GameAllocEntry));
if (ptr != NULL) {
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;
} else {
return NULL;
}
}
void GameAlloc_Free(GameAlloc* this, void* data) {
GameAllocEntry* ptr;
if (data != NULL) {
ptr = &((GameAllocEntry*)data)[-1];
ptr->prev->next = ptr->next;
ptr->next->prev = ptr->prev;
this->head = this->base.prev;
SystemArena_Free(ptr);
}
}
void GameAlloc_Cleanup(GameAlloc* this) {
GameAllocEntry* next = this->base.next;
GameAllocEntry* cur;
while (&this->base != next) {
cur = next;
next = next->next;
SystemArena_Free(cur);
}
this->head = &this->base;
this->base.next = &this->base;
this->base.prev = &this->base;
}
void GameAlloc_Init(GameAlloc* this) {
this->head = &this->base;
this->base.next = &this->base;
this->base.prev = &this->base;
}