From 13072246fabad517c5806b514b2bdd8b08c4409b Mon Sep 17 00:00:00 2001 From: Kaehvaman Date: Sun, 29 Dec 2024 20:49:05 +0400 Subject: [PATCH] add ArenaDestroy --- memory_arena/src/memory_arena.c | 13 ++++++++++++- memory_arena/src/memory_arena.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/memory_arena/src/memory_arena.c b/memory_arena/src/memory_arena.c index dd04141..ff1a68a 100644 --- a/memory_arena/src/memory_arena.c +++ b/memory_arena/src/memory_arena.c @@ -60,5 +60,16 @@ void* ArenaAlloc(Arena* arena, size_t size) Arena ArenaInit(size_t buffer_size) { void* buffer = SafeMalloc(buffer_size); - return (Arena) { buffer, buffer_size, (uintptr_t)buffer }; + return (Arena) { + .buffer = buffer, + .size = buffer_size, + .offset_ptr = (uintptr_t)buffer + }; +} + +void ArenaDestroy(Arena* arena) +{ + free(arena->buffer); + arena->offset_ptr = NULL; + arena->size = 0; } \ No newline at end of file diff --git a/memory_arena/src/memory_arena.h b/memory_arena/src/memory_arena.h index d12b88e..4b6ba34 100644 --- a/memory_arena/src/memory_arena.h +++ b/memory_arena/src/memory_arena.h @@ -18,3 +18,4 @@ typedef struct { Arena ArenaInit(size_t buffer_size); void* ArenaAlloc(Arena* arena, size_t size); void* ArenaAllocAligned(Arena* arena, size_t size, size_t alignment); +void ArenaDestroy(Arena* arena); \ No newline at end of file