|
cbase 1.46.11
C/C++ Static Template
|
Classes | |
| struct | Allocator |
| A generic allocator backed by function pointers (vtable). More... | |
Typedefs | |
| typedef void *(* | AllocFn) (void *ctx, usize size) |
| Function pointer type for an allocation operation. | |
| typedef void(* | FreeFn) (void *ctx, void *ptr, usize size) |
| Function pointer type for a free operation. | |
| typedef void *(* | ReallocFn) (void *ctx, void *ptr, usize old_size, usize new_size) |
| Function pointer type for a realloc operation. | |
| typedef struct Allocator | Allocator |
| A generic allocator backed by function pointers (vtable). | |
Functions | |
| function void * | allocator_alloc (Allocator *a, usize size) |
| Allocates size zero-initialized bytes through the allocator. | |
| function void | allocator_free (Allocator *a, void *ptr, usize size) |
| Frees a previously allocated block through the allocator. | |
| function void * | allocator_realloc (Allocator *a, void *ptr, usize old_size, usize new_size) |
| Resizes a previously allocated block through the allocator. | |
| function Allocator | arena_allocator (Arena *arena) |
| Constructs an Allocator interface backed by an existing Arena. | |
| typedef struct Allocator Allocator |
A generic allocator backed by function pointers (vtable).
Pass by pointer to any function that needs to allocate memory without caring about the concrete allocator type.
| typedef void *(* AllocFn) (void *ctx, usize size) |
Function pointer type for an allocation operation.
| ctx | Opaque allocator context (e.g., a pointer to an Arena). |
| size | Number of bytes to allocate. |
Definition at line 70 of file mem_allocator.h.
| typedef void(* FreeFn) (void *ctx, void *ptr, usize size) |
Function pointer type for a free operation.
For allocators that do not support individual frees (e.g., Arena), this may be a no-op. size is provided so implementations can track usage without storing it internally.
| ctx | Opaque allocator context. |
| ptr | Pointer previously returned by AllocFn. |
| size | The size that was originally requested. |
Definition at line 83 of file mem_allocator.h.
Function pointer type for a realloc operation.
For arena allocators, this always performs a fresh allocation (the old block is not freed).
| ctx | Opaque allocator context. |
| ptr | Existing allocation to resize (may be NULL for a fresh alloc). |
| old_size | Size of the existing allocation. |
| new_size | Desired size of the new allocation. |
Definition at line 97 of file mem_allocator.h.
Allocates size zero-initialized bytes through the allocator.
| a | Pointer to the Allocator. |
| size | Number of bytes to allocate. |
Definition at line 124 of file mem_allocator.h.
Frees a previously allocated block through the allocator.
No-op for arena-backed allocators. Always safe to call.
| a | Pointer to the Allocator. |
| ptr | Pointer to free. |
| size | The size originally requested. |
Definition at line 140 of file mem_allocator.h.

|
inline |
Resizes a previously allocated block through the allocator.
Falls back to fresh alloc + memcpy + free if .realloc == NULL.
| a | Pointer to the Allocator. |
| ptr | Existing allocation to resize (may be NULL). |
| old_size | Size of the existing allocation. |
| new_size | Desired new size. |
Definition at line 160 of file mem_allocator.h.

Constructs an Allocator interface backed by an existing Arena.
The returned Allocator holds a pointer to arena the arena must outlive any use of the returned Allocator.
Example:
| arena | Pointer to an initialized Arena. |
Definition at line 220 of file mem_allocator.h.