5 #include <ctu_arena_api.h>
30 # define CTU_TRACE_MEMORY 0
37 #define CT_ALLOC_SIZE_UNKNOWN SIZE_MAX
50 typedef void *(*mem_alloc_t)(
size_t size,
void *
user);
61 typedef void *(*mem_resize_t)(
void *ptr,
size_t new_size,
size_t old_size,
void *
user);
385 # define ARENA_RENAME(ptr, name, arena) arena_rename((const void*)(ptr), name, arena)
386 # define ARENA_REPARENT(ptr, parent, arena) arena_reparent((const void*)(ptr), (const void*)(parent), arena)
387 # define ARENA_MALLOC(size, name, parent, arena) arena_malloc_info(size, name, (const void*)(parent), arena)
388 # define ARENA_OPT_MALLOC(size, name, parent, arena) arena_opt_malloc_info(size, name, (const void*)(parent), arena)
390 # define ARENA_RENAME(arena, ptr, name)
391 # define ARENA_REPARENT(arena, ptr, parent)
392 # define ARENA_MALLOC(size, name, parent, arena) arena_malloc(size, arena)
393 # define ARENA_OPT_MALLOC(size, name, parent, arena) arena_opt_malloc(size, arena)
409 #define ARENA_IDENTIFY(ptr, name, parent, arena) \
412 ARENA_RENAME(ptr, name, arena); \
413 ARENA_REPARENT(ptr, parent, arena); \
#define RET_NOTNULL
annotate the return value as not being null
#define CT_ALLOC(...)
mark a function as allocating memory
#define STA_RELEASE
annotate a pointer as invalid after the function returns
#define CT_NODISCARD
mark a function as returning a value that must be used
#define IN_NOTNULL
annotate a parameter as not being null
#define CT_ALLOC_SIZE(...)
mark a function as allocating memory with a specific size
#define STA_READS(size)
annotate a parameter as reading expr elements
#define IN_DOMAIN(cmp, it)
annotate a parameter as being bounded by the expression of cmp and it
#define IN_STRING
annotate a parameter as being a null terminated string
CT_NODISCARD CT_ARENA_API void * arena_opt_malloc_info(size_t size, const char *name, const void *parent, arena_t *arena)
allocate memory from a custom allocator
CT_NODISCARD CT_ARENA_API void * arena_opt_malloc(size_t size, arena_t *arena)
allocate memory from a custom allocator
CT_NODISCARD CT_ARENA_API void * arena_opt_realloc(STA_RELEASE void *ptr, size_t new_size, size_t old_size, arena_t *arena)
resize a memory allocation from a custom allocator
CT_NODISCARD CT_ARENA_API char * arena_opt_strdup(const char *str, arena_t *arena)
allocate a copy of a string from a custom allocator
CT_NODISCARD CT_ARENA_API void * arena_opt_memdup(STA_READS(size) const void *ptr, size_t size, arena_t *arena)
duplicate a memory region from a custom allocator duplicate a region of memory and return a pointer t...
CT_NODISCARD CT_ARENA_API char * arena_opt_strndup(STA_READS(len) const char *str, size_t len, arena_t *arena)
allocate a copy of a string with a maximum length from a custom allocator
CT_ARENA_API void arena_opt_free(STA_RELEASE void *ptr, size_t size, arena_t *arena)
release memory from a custom allocator
void(* mem_reparent_t)(const void *ptr, const void *parent, void *user)
arena reparent callback
CT_NODISCARD CT_ARENA_API void * arena_malloc_info(size_t size, const char *name, const void *parent, arena_t *arena)
allocate memory from a custom allocator
CT_NODISCARD CT_ARENA_API void * arena_memdup(STA_READS(size) const void *ptr, size_t size, arena_t *arena)
duplicate a memory region from a custom allocator duplicate a region of memory and return a pointer t...
CT_NODISCARD CT_ARENA_API void * arena_data(arena_t *arena)
get the user data pointer from an arena
CT_NODISCARD CT_ARENA_API void * arena_malloc(size_t size, arena_t *arena)
allocate memory from a custom allocator
CT_ARENA_API void arena_reparent(const void *ptr, const void *parent, arena_t *arena)
reparent a pointer in a custom allocator
CT_NODISCARD CT_ARENA_API char * arena_strdup(const char *str, arena_t *arena)
allocate a copy of a string from a custom allocator
void *(* mem_alloc_t)(size_t size, void *user)
arena malloc callback
CT_ARENA_API void arena_rename(const void *ptr, const char *name, arena_t *arena)
rename a pointer in a custom allocator
CT_NODISCARD CT_ARENA_API char * arena_strndup(STA_READS(len) const char *str, size_t len, arena_t *arena)
allocate a copy of a string with a maximum length from a custom allocator
void(* mem_rename_t)(const void *ptr, const char *name, void *user)
arena rename callback
CT_NODISCARD CT_ARENA_API void * arena_realloc(STA_RELEASE void *ptr, size_t new_size, size_t old_size, arena_t *arena)
resize a memory allocation from a custom allocator
typedefCT_BEGIN_API struct arena_t arena_t
a memory allocator
CT_ARENA_API void arena_free(STA_RELEASE void *ptr, size_t size, arena_t *arena)
release memory from a custom allocator
void(* mem_release_t)(void *ptr, size_t size, void *user)
arena free callback
void *(* mem_resize_t)(void *ptr, size_t new_size, size_t old_size, void *user)
arena realloc callback
mem_resize_t fn_realloc
the realloc function
const char * name
the name of the allocator
mem_release_t fn_free
the free function
void * user
user data pointer
mem_reparent_t fn_reparent
the reparent function
mem_rename_t fn_rename
the rename function
mem_alloc_t fn_malloc
the malloc function