# Arena Allocator
With `--arena`, the generated header includes an arena type and three inline
helpers, and each type gains an additional `TypeName_decode_arena()` function.
The arena mode lets you release all allocations from a decode pass in a single
`synta_arena_free_all()` call instead of tracking each pointer individually.
## Arena Type and Helpers
The following types and functions are generated into the header:
```c,ignore
/* SYNTA_ARENA_CAPACITY is set in the generated header based on the schema. */
typedef struct {
void *_ptrs[SYNTA_ARENA_CAPACITY];
void (*_fns[SYNTA_ARENA_CAPACITY])(void *);
size_t _n;
} SyntaArena;
/* Initialize an arena (zeroes all fields). */
static inline void synta_arena_init(SyntaArena *arena);
/* Internal — called by generated _decode_arena() implementations. */
static inline void _synta_arena_track(SyntaArena *arena,
void *ptr,
void (*fn)(void *));
/* Free every allocation tracked by the arena. */
static inline void synta_arena_free_all(SyntaArena *arena);
```
## Additional Generated Function
```c,ignore
SyntaErrorCode TypeName_decode_arena(SyntaDecoder *decoder,
SyntaArena *arena,
TypeName *out);
```
`TypeName_decode_arena()` behaves like `TypeName_decode()` but registers every
heap allocation (OctetString, Integer, OID, items arrays) with the arena
instead of leaving them for the caller to track individually.
## Usage Pattern
```c,ignore
SyntaArena arena;
synta_arena_init(&arena);
TypeName result = {0};
SyntaErrorCode err = TypeName_decode_arena(decoder, &arena, &result);
if (err != SyntaErrorCode_Success) {
synta_arena_free_all(&arena);
return err;
}
/* use result ... */
synta_arena_free_all(&arena); /* releases all allocations at once */
```
There is no need to call `TypeName_free()` when using arena mode;
`synta_arena_free_all()` releases everything tracked by
`TypeName_decode_arena()`.
## When to Use Arena Mode
Arena mode is useful when:
- You decode many structs in a batch and want to free them all at once at the
end of the batch.
- You want to avoid tracking individual pointer lifetimes across error paths.
- You are parsing data in a request-handler loop and want a clean arena reset
between requests.
Arena mode does not reduce the number of individual allocations; it reduces
the bookkeeping needed to free them.