From 9df999df385b74be5096218d206dd39988784237 Mon Sep 17 00:00:00 2001 From: Omniscient Date: Fri, 17 May 2024 09:39:57 +1000 Subject: starting on pool allocator --- src/std/mem.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/std/mem.h') 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 +#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 -- cgit v1.2.3-70-g09d2