aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-21 13:29:38 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-21 13:29:38 -0700
commit7d254c81400128923d1952909bf22b1784e540fc (patch)
tree671ecbf2e1d18f97b29c81a6666d8fb9d6979d3c /include
parentaa064359cb514251a73b53de3e530fa89f687ab7 (diff)
feat: added simple memory arena allocator to libn
Diffstat (limited to 'include')
-rw-r--r--include/libn.h13
1 files changed, 9 insertions, 4 deletions
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