#ifndef SAND_ARENA_ALLOCATOR_H #define SAND_ARENA_ALLOCATOR_H // This module defines an arena allocator which implements `SandAllocator`. It // is useful if one needs to allocate a lot of objects with the same lifetime // very quickly. When the arena is destroyed, all objects allocated within are // freed. #include "allocator.h" // This should only be used internally by an arena allocator. // It is only public because of C's stone-age """modules""". typedef struct _SandRegion { struct _SandRegion *prev; size_t capacity; size_t used; unsigned char data[]; } SandRegion; typedef struct { SandAllocator *parent; SandRegion *current_region; } SandArena; SandArena sand_create_arena(SandAllocator *parent); // Returns a `SandAllocator` which is valid as long as the arena is. // The arena must not be moved afterwards, as the allocator retains a pointer to the arena. SandAllocator sand_get_allocator_for_arena(SandArena *); void sand_destroy_arena(SandArena *); #endif