|
data-structures-c
|
Arena allocator. More...
#include <stddef.h>Go to the source code of this file.
Macros | |
| #define | FUNCTION_LINKAGE |
| Specify function linkage e.g. static inline. | |
| #define | IS_POW2(X) |
| Macro to check if a number is a power of two. | |
Functions | |
| struct arena_state | arena_state_save (struct arena *arena_ptr) |
| Save the arena state temporarily. | |
| void | arena_state_restore (struct arena_state prev_state) |
| Restore the arena state. | |
| void | arena_init (void *self_, const size_t len, unsigned char *backing_buf) |
| Initialize the arena. | |
| void | arena_deallocate_all (void *self_) |
| Deallocate all allocations in the arena. | |
| void | arena_deallocate (void *self_, void *mem) |
| Dummy no-op deallocate function. | |
| void * | arena_allocate_aligned (void *self_, const size_t alignment, const size_t size) |
| Get the pointer to a chunk of the arena. With specific alignment. | |
| void * | arena_allocate (void *self_, const size_t size) |
| Get the pointer to a chunk of the arena. | |
| void * | arena_reallocate_aligned (void *self_, void *old_ptr_, const size_t alignment, const size_t old_size, const size_t new_size) |
| Reallocate a previously allocated chunk in the arena. With specific aligment. | |
| void * | arena_reallocate (void *self_, void *old_ptr, const size_t old_size, const size_t new_size) |
| Reallocate a previously allocated chunk in the arena. | |
Arena allocator.
For a comprehensive source, read:
| #define IS_POW2 | ( | X | ) |
Macro to check if a number is a power of two.
| [in] | X | The number at hand. |
| void * arena_allocate | ( | void * | self_, |
| const size_t | size ) |
Get the pointer to a chunk of the arena.
| [in] | self_ | The arena pointer. |
| [in] | size | The section size in bytes. |
| NULL | If the arena doesn't have enough memory for the allocation. |
| void * arena_allocate_aligned | ( | void * | self_, |
| const size_t | alignment, | ||
| const size_t | size ) |
Get the pointer to a chunk of the arena. With specific alignment.
| [in] | self_ | arena pointer. |
| [in] | alignment | alignment size |
| [in] | size | chunk size |
| NULL | If the arena doesn't have enough memory for the allocation. |
| void arena_deallocate | ( | void * | self_, |
| void * | mem ) |
| void arena_deallocate_all | ( | void * | self_ | ) |
Deallocate all allocations in the arena.
| [in] | self_ | Arena pointer. |
| void arena_init | ( | void * | self_, |
| const size_t | len, | ||
| unsigned char * | backing_buf ) |
Initialize the arena.
| [in] | self_ | Arena pointer. |
| [in] | len | Backing buffer length. |
| [in] | backing_buf | Backing buffer. |
| void * arena_reallocate | ( | void * | self_, |
| void * | old_ptr, | ||
| const size_t | old_size, | ||
| const size_t | new_size ) |
Reallocate a previously allocated chunk in the arena.
| [in] | self_ | The arena pointer. |
| [in] | old_ptr | Pointer to the buffer to reallocate |
| [in] | old_size | Old size. |
| [in] | new_size | New size to grow/shrink to. |
| NULL | If arena doesn't have enough memory for the reallocation or invalid parameters are given. |
| void * arena_reallocate_aligned | ( | void * | self_, |
| void * | old_ptr_, | ||
| const size_t | alignment, | ||
| const size_t | old_size, | ||
| const size_t | new_size ) |
Reallocate a previously allocated chunk in the arena. With specific aligment.
| [in] | self_ | Arena pointer. |
| [in] | old_ptr_ | Pointer to the buffer to reallocate |
| [in] | alignment | Alignment size. |
| [in] | old_size | Old size. |
| [in] | new_size | New size to grow/shrink to. |
| NULL | If arena doesn't have enough memory for the reallocation or invalid parameters are given. |
| void arena_state_restore | ( | struct arena_state | prev_state | ) |
Restore the arena state.
| [in] | prev_state | Stored arena state. |
| struct arena_state arena_state_save | ( | struct arena * | arena_ptr | ) |
Save the arena state temporarily.
| [in] | arena_ptr | The arena whose state to save. |