Arena allocator.
More...
#include "align.h"
#include "is_pow2.h"
#include <assert.h>
#include <stdalign.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
|
static void | arena_init (struct arena *self, const size_t len, unsigned char *backing_buf) |
| Initialize the arena.
|
|
static void | arena_deallocate_all (struct arena *self) |
| Deallocate all allocations in the arena.
|
|
static void * | arena_allocate_aligned (struct arena *self, const size_t alignment, const size_t size) |
| Get the pointer to a chunk of the arena. With specific alignment.
|
|
static void * | arena_allocate (struct arena *self, const size_t size) |
| Get the pointer to a chunk of the arena.
|
|
static void * | arena_reallocate_aligned (struct arena *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.
|
|
static void * | arena_reallocate (struct arena *self, void *old_ptr, const size_t old_size, const size_t new_size) |
| Reallocate a previously allocated chunk in the arena.
|
|
static struct temp_arena_state | temp_arena_state_save (struct arena *arena_ptr) |
| Save the arena state temporarily.
|
|
static void | temp_arena_state_restore (struct temp_arena_state prev_state) |
| Restore the arena state.
|
|
Arena allocator.
For a comprehensive source, read:
◆ arena_allocate()
static void * arena_allocate |
( |
struct arena * | self, |
|
|
const size_t | size ) |
|
inlinestatic |
Get the pointer to a chunk of the arena.
- Parameters
-
[in] | self | The arena pointer. |
[in] | size | The section size in bytes. |
- Returns
- A pointer to a zeroed-out memory chunk.
- Return values
-
NULL | If the arena doesn't have enough memory for the allocation. |
◆ arena_allocate_aligned()
static void * arena_allocate_aligned |
( |
struct arena * | self, |
|
|
const size_t | alignment, |
|
|
const size_t | size ) |
|
inlinestatic |
Get the pointer to a chunk of the arena. With specific alignment.
- Parameters
-
[in] | self | arena pointer. |
[in] | alignment | alignment size |
[in] | size | chunk size |
- Returns
- A pointer to a zeroed-out memory chunk.
- Return values
-
NULL | If the arena doesn't have enough memory for the allocation. |
◆ arena_deallocate_all()
static void arena_deallocate_all |
( |
struct arena * | self | ) |
|
|
inlinestatic |
Deallocate all allocations in the arena.
- Parameters
-
◆ arena_init()
static void arena_init |
( |
struct arena * | self, |
|
|
const size_t | len, |
|
|
unsigned char * | backing_buf ) |
|
inlinestatic |
Initialize the arena.
- Parameters
-
[in] | self | Arena pointer. |
[in] | len | Backing buffer length. |
[in] | backing_buf | Backing buffer. |
◆ arena_reallocate()
static void * arena_reallocate |
( |
struct arena * | self, |
|
|
void * | old_ptr, |
|
|
const size_t | old_size, |
|
|
const size_t | new_size ) |
|
inlinestatic |
Reallocate a previously allocated chunk in the arena.
- Parameters
-
[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. |
- Returns
- A pointer to the reallocated memory chunk.
- Return values
-
NULL | If arena doesn't have enough memory for the reallocation or invalid parameters are given. |
◆ arena_reallocate_aligned()
static void * arena_reallocate_aligned |
( |
struct arena * | self, |
|
|
void * | old_ptr_, |
|
|
const size_t | alignment, |
|
|
const size_t | old_size, |
|
|
const size_t | new_size ) |
|
inlinestatic |
Reallocate a previously allocated chunk in the arena. With specific aligment.
- Parameters
-
[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. |
- Returns
- A pointer to the reallocated memory chunk.
- Return values
-
NULL | If arena doesn't have enough memory for the reallocation or invalid parameters are given. |
◆ temp_arena_state_restore()
Restore the arena state.
- Parameters
-
[in] | prev_state | Stored arena state. |
◆ temp_arena_state_save()
Save the arena state temporarily.
- Parameters
-
[in] | arena_ptr | The arena whose state to save. |