add ArenaDestroy

This commit is contained in:
Kaehvaman 2024-12-29 20:49:05 +04:00
parent 84cb7fba0c
commit 13072246fa
2 changed files with 13 additions and 1 deletions

View File

@ -60,5 +60,16 @@ void* ArenaAlloc(Arena* arena, size_t size)
Arena ArenaInit(size_t buffer_size) Arena ArenaInit(size_t buffer_size)
{ {
void* buffer = SafeMalloc(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;
} }

View File

@ -18,3 +18,4 @@ typedef struct {
Arena ArenaInit(size_t buffer_size); Arena ArenaInit(size_t buffer_size);
void* ArenaAlloc(Arena* arena, size_t size); void* ArenaAlloc(Arena* arena, size_t size);
void* ArenaAllocAligned(Arena* arena, size_t size, size_t alignment); void* ArenaAllocAligned(Arena* arena, size_t size, size_t alignment);
void ArenaDestroy(Arena* arena);