Practice ยท 4 of 4
A Tiny Arena (Own Once, Free Once)
Implement a bump allocator (arena) โ one ownership boundary for many
small allocations:
``c
typedef struct { unsigned char *buf; size_t cap, used; } Arena; /* in boilerplate */
int arena_init(Arena *a, size_t cap); /* malloc cap bytes; 0 on failure */
/* returns cap bytes of zeroed space inside the arena, or NULL if full */
void *arena_alloc(Arena *a, size_t n);
/* frees the whole arena in one free; zeroes the struct */
void arena_destroy(Arena *a);
``
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Ownership Patterns Gym