|
cbase 1.50.0
C/C++ Static Template
|
A vtable structure for passing allocators dynamically. More...
Classes | |
| struct | MemAllocator |
| An abstract allocator interface. More... | |
Typedefs | |
| typedef enum MemAllocMode | MemAllocMode |
| Describes the type of memory operation being requested. | |
| typedef void *(* | MemAllocFn) (MemAllocMode mode, void *ctx, usize size, void *old_ptr) |
| The core function signature for an abstract allocator. | |
| typedef struct MemAllocator | MemAllocator |
| An abstract allocator interface. | |
Enumerations | |
| enum | MemAllocMode { MEM_ALLOC_MODE_ALLOC , MEM_ALLOC_MODE_FREE , MEM_ALLOC_MODE_REALLOC , MEM_ALLOC_MODE_FREE_ALL } |
| Describes the type of memory operation being requested. More... | |
Functions | |
| 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. | |
| function void | mem_free (MemAllocator *alloc, void *ptr, usize size) |
| Frees a previously allocated block through the allocator. | |
| function void | mem_free_all (MemAllocator *alloc) |
| Clears the entire allocator in one shot (e.g. arena reset, pool reset). | |
A vtable structure for passing allocators dynamically.
| typedef void *(* MemAllocFn) (MemAllocMode mode, void *ctx, usize size, void *old_ptr) |
The core function signature for an abstract allocator.
| mode | The memory operation being requested. |
| ctx | The internal context/state of the allocator (e.g., pointer to an Arena). |
| size | The size of the requested allocation. |
| old_ptr | A pointer to existing memory (used during FREE and REALLOC modes). |
Definition at line 80 of file mem_allocator.h.
| enum MemAllocMode |
Describes the type of memory operation being requested.
Definition at line 65 of file mem_allocator.h.
|
inline |
Allocator Helper Functions.
Allocates size zero-initialized bytes through the allocator.
Example:
| alloc | Pointer to the allocator. |
| size | Number of bytes to allocate. |
Definition at line 105 of file mem_allocator.h.

|
inline |
Frees a previously allocated block through the allocator.
No-op for arena allocators. Always safe to call regardless of allocator type.
Example:
| alloc | Pointer to the allocator. |
| ptr | Pointer to free. |
| size | The size originally requested. |
Definition at line 166 of file mem_allocator.h.
|
inline |
Clears the entire allocator in one shot (e.g. arena reset, pool reset).
For arena allocators this resets pos to 0. For heap allocators this is a no-op. Use this instead of manually calling mem_arena_clear() so that code stays allocator-agnostic.
| alloc | Pointer to the allocator to clear. |
Definition at line 181 of file mem_allocator.h.
|
inline |
Resizes a previously allocated block through the allocator.
For arena allocators this always allocates a fresh block and copies the old data — the old block is not freed since arenas don't support individual frees. For heap allocators this maps to realloc.
Example:
| alloc | Pointer to the allocator. |
| old_ptr | Existing allocation to resize. |
| old_size | Size of the existing allocation in bytes. |
| new_size | Desired new size in bytes. |
Definition at line 135 of file mem_allocator.h.