An implementation of the Arena Allocator in C and C++.
Advantages:
- Very fast allocation
- No per-allocation heap overhead
- Easy bulk deallocation through reset
Tradeoffs:
- Individual allocations cannot be freed
- Memory is reclaimed all at once
Essentially reserves a whole block of memory and just uses pointer arithmetic rather than new allocations each call. This makes it much more efficient.
├── c
│ ├── examples
│ │ └── main.c
│ ├── include
│ │ └── arena.h
│ ├── Makefile
│ ├── src
│ │ └── arena.c
│ └── tests
│ └── test_arena.c
├── c++
│ ├── arena_example
│ ├── arena_test
│ ├── examples
│ │ └── main.cpp
│ ├── include
│ │ └── arena.h
│ ├── Makefile
│ ├── src
│ │ └── arena.cpp
│ └── tests
│ └── test_arena.cpp
└── README.md
To build the arena file with my example, in either C or C++ directory:
make
You can also run the tests I made:
make test
Arena arena(1024);
void* ptr = arena.alloc(64);
arena.reset();