From 7d254c81400128923d1952909bf22b1784e540fc Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 21 Apr 2020 13:29:38 -0700 Subject: feat: added simple memory arena allocator to libn --- include/libn.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/libn.h b/include/libn.h index 74e230e..0fbcdc7 100644 --- a/include/libn.h +++ b/include/libn.h @@ -50,14 +50,19 @@ void _bufpop(void*, int, vlong); // ----------------------------------------------------------------------------- // Memory allocation -// TODO: Think about interface here. -typedef struct Allocator { +typedef struct mem·Allocator { void *(*alloc)(ulong size); void *(*realloc)(void *ptr, ulong size); void (*free)(void *ptr); -} Allocator; +} mem·Allocator; -static Allocator mem·sys = { .alloc = &malloc, .realloc = &realloc, .free = &free}; +static mem·Allocator mem·sys = { .alloc = &malloc, .realloc = &realloc, .free = &free }; + +typedef struct mem·Arena mem·Arena; + +mem·Arena *mem·newarena(mem·Allocator from); +void *mem·arenaalloc(mem·Arena *A, ulong size); +void mem·freearena(mem·Arena *A); // ----------------------------------------------------------------------------- // Co-routines -- cgit v1.2.1