From aa064359cb514251a73b53de3e530fa89f687ab7 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 21 Apr 2020 12:38:03 -0700 Subject: feat: added allocator interface to allow for flexible library interfaces --- include/libn.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include') diff --git a/include/libn.h b/include/libn.h index 64e2e70..74e230e 100644 --- a/include/libn.h +++ b/include/libn.h @@ -47,6 +47,18 @@ typedef struct bufHdr void* bufgrow(void*, vlong, vlong); void _bufpop(void*, int, vlong); +// ----------------------------------------------------------------------------- +// Memory allocation + +// TODO: Think about interface here. +typedef struct Allocator { + void *(*alloc)(ulong size); + void *(*realloc)(void *ptr, ulong size); + void (*free)(void *ptr); +} Allocator; + +static Allocator mem·sys = { .alloc = &malloc, .realloc = &realloc, .free = &free}; + // ----------------------------------------------------------------------------- // Co-routines -- cgit v1.2.1