summaryrefslogtreecommitdiff
path: root/src/std/mem.h
diff options
context:
space:
mode:
authorOmniscient <omniscient.oce@gmail.com>2024-05-17 09:39:57 +1000
committerOmniscient <omniscient.oce@gmail.com>2024-05-17 09:39:57 +1000
commit9df999df385b74be5096218d206dd39988784237 (patch)
tree9ade81031095c70b5efb162920393903797e7ed4 /src/std/mem.h
parente61a2e43947cebaafe4c3725414d33e092bb6fad (diff)
starting on pool allocator
Diffstat (limited to 'src/std/mem.h')
-rw-r--r--src/std/mem.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/std/mem.h b/src/std/mem.h
index bbfb852..eef97a0 100644
--- a/src/std/mem.h
+++ b/src/std/mem.h
@@ -10,6 +10,9 @@
#pragma once
#include <stddef.h>
+#include "defines.h"
+
+// --- Arena
// Inspired by https://nullprogram.com/blog/2023/09/27/
typedef struct arena {
@@ -30,4 +33,27 @@ void arena_free_all(arena* a);
void arena_free_storage(arena* a);
arena_save arena_savepoint(arena* a);
void arena_rewind(arena_save savepoint);
-// TODO: arena_resize \ No newline at end of file
+// TODO: arena_resize
+
+// --- Pool
+
+typedef struct void_pool_header void_pool_header;
+struct void_pool_header {
+ void_pool_header* next;
+};
+
+typedef struct void_pool {
+ u64 capacity;
+ u64 entry_size;
+ u64 count;
+ void* backing_buffer;
+ void_pool_header* free_list_head;
+} void_pool;
+
+void_pool void_pool_create(arena* a, u64 capacity, u64 entry_size);
+void void_pool_free_all(void_pool* pool);
+bool void_pool_is_empty(void_pool* pool);
+bool void_pool_is_full(void_pool* pool);
+void* void_pool_get(u32 raw_handle);
+
+// TODO: macro that lets us specialise