# introduce std.heap.ArenaAllocator and std.heap.DirectAllocator · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/445b03384a5ffcace11927aa9dd5f21604527f5c)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 445b03384a5ffcace11927aa9dd5f21604527f5c

Requested commit: 445b03384a5ffcace11927aa9dd5f21604527f5c

Commit: 445b03384a5ffcace11927aa9dd5f21604527f5c

Tree: 9cab533e7ac95f74d0aad7e986f86d0f7a2c307e

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
introduce std.heap.ArenaAllocator and std.heap.DirectAllocator

 * DirectAllocator does the underlying syscall for every allocation.
 * ArenaAllocator takes another allocator as an argument and
   allocates bytes up front, falling back to DirectAllocator with
   increasingly large allocation sizes, to avoid calling it too often.
   Then the entire arena can be freed at once.

The self hosted parser is updated to take advantage of ArenaAllocator
for the AST that it returns. This significantly reduces the complexity
of cleanup code.

docgen and build runner are updated to use the combination of
ArenaAllocator and DirectAllocator instead of IncrementingAllocator,
which is now deprecated in favor of FixedBufferAllocator combined
with DirectAllocator.

The C allocator calls aligned_alloc instead of malloc, in order to
respect the alignment parameter.

Added asserts in Allocator to ensure that implementors of the
interface return slices of the correct size.

Fixed a bug in Allocator when you call realloc to grow the allocation.

```

## Parents

- [f2d601661d286b135293373a83ce1a8628272379](https://git.cafe/gitcafe/zig/commit/f2d601661d286b135293373a83ce1a8628272379?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/445b03384a5ffcace11927aa9dd5f21604527f5c?format=markdown)
