Update README

This commit is contained in:
2023-08-19 01:27:52 +02:00
parent 069f6b11dc
commit 44a2982376

View File

@@ -1,4 +1,20 @@
# Arena Allocator
Arena allocators are region based allocators that tie many allocations to a
single region of memory. Benefits are massivly simplified allocation and
deallocation for complex structures, increased performance due to improved
cache locality, and reduced memory fragmentation as long as individual items
don't need to be deallocated. For programs that need to micro-manage individual
allocations this is not an ideal solution.
Deallocating a region of memory with arenas is extremely fast, because the arena
length is just set to 0. Allocating memory is also extremely fast.
This implementation also grows the arena on demand using mmap and mprotect.
Extending the library with a new type of allocation strategy should be easy.
# Reference
## `arena_t arena_new()` ## `arena_t arena_new()`
Allocate a new arena. Allocate a new arena.
@@ -25,13 +41,11 @@ Detach an arena from an existing memory region.
Reset an arena. Reset an arena.
## `void *arena_alloc(arena_t *a, size_t len)` ## `void *arena_alloc(arena_t *a, size_t len)`
Allocate memory from an arena. Allocate memory from an arena.
Returns NULL and sets errno on failure. Returns NULL and sets errno on failure.
## `void *arena_calloc(arena_t *a, size_t nmemb, size_t size)` ## `void *arena_calloc(arena_t *a, size_t nmemb, size_t size)`
Allocate and zero memory from an arena. Allocate and zero memory from an arena.
Returns NULL and sets errno on failure. Returns NULL and sets errno on failure.