![]() |
libghostty-vt 0.0.0
|
Run the library on your own memory allocator. More...
Run the library on your own memory allocator.
An allocator is the set of functions libghostty-vt calls to get and free memory.
Most programs never need this. Any function that takes a const GhosttyAllocator* accepts NULL, which selects the default allocator. You only need your own to run the library on memory you control.
Full program: c-vt-allocator/src/main.c
See Memory for what the default is, how to write your own allocator, and how to free memory the library gives you.
Functions | |
| GHOSTTY_API uint8_t * | ghostty_alloc (const GhosttyAllocator *allocator, size_t len) |
| GHOSTTY_API void | ghostty_free (const GhosttyAllocator *allocator, uint8_t *ptr, size_t len) |
Data Structures | |
| struct | GhosttyAllocatorVtable |
| struct | GhosttyAllocator |
| GHOSTTY_API uint8_t * ghostty_alloc | ( | const GhosttyAllocator * | allocator, |
| size_t | len ) |
Allocate a buffer of len bytes.
Uses the provided allocator, or the default allocator if NULL is passed. The returned buffer must be freed with ghostty_free() using the same allocator.
| allocator | Pointer to the allocator to use, or NULL for the default |
| len | Number of bytes to allocate |
| GHOSTTY_API void ghostty_free | ( | const GhosttyAllocator * | allocator, |
| uint8_t * | ptr, | ||
| size_t | len ) |
Free memory that was allocated by a libghostty-vt function.
Use this to free buffers returned by functions such as ghostty_formatter_format_alloc(). Pass the same allocator that was used for the allocation, or NULL if the default allocator was used.
Use this instead of the C free(), which can use a different heap than the library. See Allocating and Freeing Buffers for why.
Passing a NULL ptr does nothing.
| allocator | Pointer to the allocator that was used to allocate the memory, or NULL if the default allocator was used |
| ptr | Pointer to the memory to free (may be NULL) |
| len | Length of the allocation in bytes (must match the original allocation size) |