![]() |
libghostty-vt 1.0.0
|
#include <ghostty/vt/allocator.h>
Data Fields | |
| GhosttyAllocatorAllocFn | alloc |
| GhosttyAllocatorResizeFn | resize |
| GhosttyAllocatorRemapFn | remap |
| GhosttyAllocatorFreeFn | free |
| void * | reserved [4] |
The functions that make up a custom allocator.
alloc and free are required. resize and remap are optional, and when they are NULL the library grows memory by allocating a new block, copying, and freeing the old one. See Writing a Custom Allocator for a complete example and Alignment for an explanation of alignment.
Every function receives the ctx pointer from the GhosttyAllocator it belongs to. When the library resizes, remaps, or frees memory, it always passes the same alignment it used for the original allocation and the current length of the block, so your allocator does not need to record either.
Every function also receives ret_addr, the address of the code that requested the memory, or 0 if it is unknown. Allocators that track leaks or report where memory came from can use it. Most allocators ignore it.
Initialize the whole struct to zero before setting the fields you use, so the reserved slots are NULL.
The interface matches Zig's std.mem.Allocator. The library is written in Zig, so this lets it use your allocator directly, and it is an interface already proven by a wide range of allocators in the Zig ecosystem. Simple allocators can ignore most of the arguments. Zig's own libc allocator (CAllocator in lib/std/heap.zig) is a good short reference.
Definition at line 173 of file allocator.h.
| GhosttyAllocatorAllocFn alloc |
Allocates a block. Required.
Definition at line 175 of file allocator.h.
Frees a block. Required.
Definition at line 184 of file allocator.h.
| GhosttyAllocatorRemapFn remap |
Resizes a block and may move it. Optional.
Definition at line 181 of file allocator.h.
| void* reserved[4] |
Reserved for future versions. Must be NULL.
These slots let a future release add new allocator functions without changing the size of this struct. The library ignores any slot it does not know about, so leaving them NULL keeps your code working with future versions.
Debug builds of the library stop with an error if a reserved slot is not NULL, to catch a vtable that was not zero-initialized.
Definition at line 197 of file allocator.h.
| GhosttyAllocatorResizeFn resize |
Resizes a block without moving it. Optional.
Definition at line 178 of file allocator.h.