82 size_t used_aligned = (arena->
current->
used + alignment - 1) & ~(alignment - 1);
83 size_t needed = used_aligned + size;
85 if (used_aligned >= arena->
current->
used && needed >= used_aligned && needed <= arena->current->capacity) {
106 memset(ptr, 0, size);
123 memcpy(dst, src, size);
void pm_arena_reserve(pm_arena_t *arena, size_t capacity)
Ensure the arena has at least capacity bytes available in its current block, allocating a new block i...
struct pm_arena_block pm_arena_block_t
A single block of memory in the arena.
void * pm_arena_alloc_slow(pm_arena_t *arena, size_t size)
Slow path for pm_arena_alloc: allocate a new block and return a pointer to the first size bytes.
static void * pm_arena_memdup(pm_arena_t *arena, const void *src, size_t size, size_t alignment)
Allocate memory from the arena and copy the given data into it.
static PRISM_FORCE_INLINE void * pm_arena_alloc(pm_arena_t *arena, size_t size, size_t alignment)
Allocate memory from the arena.
PRISM_EXPORTED_FUNCTION void pm_arena_free(pm_arena_t *arena)
Free all blocks in the arena.
static void * pm_arena_zalloc(pm_arena_t *arena, size_t size, size_t alignment)
Allocate zero-initialized memory from the arena.
Macro definitions used throughout the prism library.
#define PRISM_FORCE_INLINE
Force a function to be inlined at every call site.
#define PM_FLEX_ARY_LEN
A macro for defining a flexible array member.
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
A single block of memory in the arena.
struct pm_arena_block * prev
The previous block in the chain (for freeing).
char data[PM_FLEX_ARY_LEN]
The block's data.
size_t used
The number of bytes consumed so far.
size_t capacity
The total usable bytes in data[].
size_t block_count
The number of blocks allocated.
pm_arena_block_t * current
The active block (allocate from here).