6#ifndef __CWIST_CORE_MEM_ALLOC_H__
7#define __CWIST_CORE_MEM_ALLOC_H__
10#include <ttak/mem/owner.h>
61#if defined(__GNUC__) || defined(__clang__)
62#define CWIST_ATTRIBUTE_CLEANUP(func) __attribute__((cleanup(func)))
64#define CWIST_ATTRIBUTE_CLEANUP(func)
73static inline void cwist_defer_free_cb(
void *pp) {
74 void **p = (
void **)pp;
101#define CWIST_DEFER_FREE CWIST_ATTRIBUTE_CLEANUP(cwist_defer_free_cb)
116#define cwist_alloc_scoped(var, cast, size) \
117 void *_cwist_scoped_##var CWIST_DEFER_FREE = cwist_alloc(size); \
118 cast var = (cast)_cwist_scoped_##var
145static inline void *cwist_scratch_alloc(
cwist_scratch_t *s,
size_t size) {
163static inline void cwist_scratch_cleanup(
void *sp) {
190#define CWIST_SCRATCH_DEFER CWIST_ATTRIBUTE_CLEANUP(cwist_scratch_cleanup)
void cwist_free(void *ptr)
Free memory obtained via cwist_alloc/cwist_strdup/etc.
void * cwist_realloc(void *ptr, size_t new_size)
Resize an existing allocation (libttak tracked).
char * cwist_strdup(const char *src)
Duplicate a string using libttak-backed storage.
void * cwist_malloc(size_t size)
Allocate zeroed memory via the CWIST owner context.
void * cwist_alloc_array(size_t count, size_t elem_size)
Allocate zeroed memory for count elements.
ttak_owner_t * cwist_create_owner(void)
Lazily create (or return) the shared CWIST owner context.
char * cwist_strndup(const char *src, size_t n)
Duplicate up to n bytes of a string (libttak-backed).
void * cwist_alloc(size_t size)
Allocate zeroed memory tracked by libttak.
Request-scoped arena allocator backed by libttak arena generations.
struct cwist_arena cwist_arena_t
void * cwist_arena_alloc(cwist_arena_t *arena, size_t size)
Bump-allocate size bytes from the active generation.
void cwist_arena_destroy(cwist_arena_t *arena)
Retire the generation and destroy the arena, releasing every allocation made from it at once.
cwist_arena_t * cwist_arena_create(size_t generation_bytes)
Create an arena backed by a recycled thread-local generation buffer.
Backing state for cwist_scratch_alloc()/CWIST_SCRATCH_DEFER: a single block-scoped allocation that pr...