summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2023-08-06 14:14:33 -0400
committerGitHub <noreply@github.com>2023-08-06 14:14:33 -0400
commitbd0c96e41818de39d243604f2a56bdee779956f2 (patch)
treea26ed55cebc7cf7b7dfcedaf617e8f35cf1d15e5 /src/code
parent49676377a38a3dfd2d6a50e885d7fb814e1e377b (diff)
`gamealloc.c` (#33)
* C file * match file * review
Diffstat (limited to 'src/code')
-rw-r--r--src/code/gamealloc.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/code/gamealloc.c b/src/code/gamealloc.c
new file mode 100644
index 0000000..f953028
--- /dev/null
+++ b/src/code/gamealloc.c
@@ -0,0 +1,60 @@
+#include "gamealloc.h"
+#include "malloc.h"
+#include "libc/stdint.h"
+
+void func_800D3720_jp(GameAlloc* this) {
+ GameAllocEntry* iter = this->base.next;
+
+ while (&this->base != iter) {
+ iter = iter->next;
+ }
+}
+
+void* gamealloc_malloc(GameAlloc* this, size_t size) {
+ GameAllocEntry* ptr = 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;
+ }
+
+ return NULL;
+}
+
+void gamealloc_free(GameAlloc* this, void* ptr) {
+ if (ptr != NULL) {
+ GameAllocEntry* entry = (GameAllocEntry*)ptr - 1;
+
+ entry->prev->next = entry->next;
+ entry->next->prev = entry->prev;
+ this->head = this->base.prev;
+ free(entry);
+ }
+}
+
+void gamealloc_cleanup(GameAlloc* this) {
+ GameAllocEntry* iter = this->base.next;
+
+ while (&this->base != iter) {
+ GameAllocEntry* cur = iter;
+
+ iter = iter->next;
+ 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;
+}