50#ifndef MEM_ALLOCATOR_H
51#define MEM_ALLOCATOR_H
139 if (new_ptr != NULL && new_ptr != old_ptr) {
140 MEM_COPY(new_ptr, old_ptr,
MIN(old_size, new_size));
208#define MAKE(type, count, alloc) ((type *)mem_alloc((alloc), sizeof(type) * (count)))
223#define MAKE_STRUCT(type, alloc) ((type *)mem_alloc((alloc), sizeof(type)))
235#define RELEASE(type, count, ptr, alloc) mem_free((alloc), (ptr), sizeof(type) * (count))
Context detection, compiler abstractions, utility macros, and data structures.
Core fixed-width type aliases and memory size constants.
#define function
File-scoped function (invisible to the linker).
#define C_LINKAGE_END
Closes a C linkage block for C++ compilers (Empty in C).
#define C_LINKAGE_BEGIN
Opens a C linkage block for C++ compilers (Empty in C).
void *(* MemAllocFn)(MemAllocMode mode, void *ctx, usize size, void *old_ptr)
The core function signature for an abstract allocator.
MemAllocMode
Describes the type of memory operation being requested.
function void mem_free_all(MemAllocator *alloc)
Clears the entire allocator in one shot (e.g. arena reset, pool reset).
function void mem_free(MemAllocator *alloc, void *ptr, usize size)
Frees a previously allocated block through the allocator.
function void * mem_alloc(MemAllocator *alloc, usize size)
Allocator Helper Functions.
function void * mem_realloc(MemAllocator *alloc, void *old_ptr, usize old_size, usize new_size)
Resizes a previously allocated block through the allocator.
@ MEM_ALLOC_MODE_FREE_ALL
#define MEM_COPY(dst, src, size)
Copies memory using memmove (overlap-safe).
#define MIN(a, b)
Returns the minimum of two values (Standard C fallback).
An abstract allocator interface.