diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-08-31 10:16:15 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-08-31 10:16:15 -0400 |
commit | 5f736eada55f84c7499103faf7c181b80eb7092f (patch) | |
tree | eb7897dfd62a726e5e4325ffd7833448f9350bc4 /src/alloc.c | |
parent | f34baf1a2f42259a4873f6d9733078003184d4e4 (diff) | |
download | bfs-5f736eada55f84c7499103faf7c181b80eb7092f.tar.xz |
alloc: New [v]arena_clear() functions
Diffstat (limited to 'src/alloc.c')
-rw-r--r-- | src/alloc.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/alloc.c b/src/alloc.c index 56d8763..8a4dc3a 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -163,11 +163,19 @@ void arena_free(struct arena *arena, void *ptr) { sanitize_free(chunk, arena->size); } -void arena_destroy(struct arena *arena) { +void arena_clear(struct arena *arena) { for (size_t i = 0; i < arena->nslabs; ++i) { free(arena->slabs[i]); } free(arena->slabs); + + arena->chunks = NULL; + arena->nslabs = 0; + arena->slabs = NULL; +} + +void arena_destroy(struct arena *arena) { + arena_clear(arena); sanitize_uninit(arena); } @@ -280,6 +288,12 @@ void varena_free(struct varena *varena, void *ptr, size_t count) { arena_free(arena, ptr); } +void varena_clear(struct varena *varena) { + for (size_t i = 0; i < varena->narenas; ++i) { + arena_clear(&varena->arenas[i]); + } +} + void varena_destroy(struct varena *varena) { for (size_t i = 0; i < varena->narenas; ++i) { arena_destroy(&varena->arenas[i]); |