diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-05-09 02:09:02 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-05-09 02:09:14 +0200 |
commit | 20fa17a5f2a286f44bdafff6dc4bb58e7667fe46 (patch) | |
tree | 434e02ca63f4f88a059433a4eedbd83bacc7da53 /include | |
parent | 8f6d296a23675687177afd697cb28d195252466e (diff) |
Implement arena allocation resizing
Diffstat (limited to 'include')
-rw-r--r-- | include/alloc.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/include/alloc.h b/include/alloc.h index 3074b27..57e7f59 100644 --- a/include/alloc.h +++ b/include/alloc.h @@ -11,7 +11,7 @@ struct _region { size_t len, cap; - void *data; + void *data, *last; struct _region *next; }; @@ -31,12 +31,17 @@ mkarena(size_t n) return (arena){._init = n ? n : MLIB_ARENA_BLKSIZE}; } +/* Arena allocation functions */ [[nodiscard, gnu::malloc, gnu::alloc_size(2, 3), gnu::alloc_align(4)]] void *arena_alloc(arena *, size_t, size_t, size_t); - +[[nodiscard]] +void *arena_realloc(arena *, void *, size_t, size_t, size_t, size_t); void arena_zero(arena *); void arena_free(arena *); +/* Arena allocation macro wrappers */ #define arena_new(a, T, n) ((T *)arena_alloc((a), (n), sizeof(T), alignof(T))) +#define arena_resz(a, T, p, n) \ + ((T *)arena_realloc((a), (p), (n), sizeof(T), alignof(T))) #endif /* !MLIB_ALLOC_H */ |