GhosttyAllocatorVtable class final

Function table for custom memory allocator operations.

This vtable defines the interface for a custom memory allocator. All function pointers must be valid and non-NULL.

@ingroup allocator

If you're not going to use a custom allocator, you can ignore all of this. All functions that take an allocator pointer allow NULL to use a default allocator.

The interface is based on the Zig allocator interface. I'll say up front that it is easy to look at this interface and think "wow, this is really overcomplicated". The reason for this complexity is well thought out by the Zig folks, and it enables a diverse set of allocation strategies as shown by the Zig ecosystem. As a consolation, please note that many of the arguments are only needed for advanced use cases and can be safely ignored in simple implementations. For example, if you look at the Zig implementation of the libc allocator in lib/std/heap.zig (search for CAllocator), you'll see it is very simple.

We chose to align with the Zig allocator interface because:

  1. It is a proven interface that serves a wide variety of use cases in the real world via the Zig ecosystem. It's shown to work.

  2. Our core implementation itself is Zig, and this lets us very cheaply and easily convert between C and Zig allocators.

NOTE(mitchellh): In the future, we can have default implementations of resize/remap and allow those to be null.

Inheritance
Implemented types
Available extensions

Constructors

GhosttyAllocatorVtable()

Properties

address Pointer<T>

Available on T, provided by the StructAddress extension

The memory address of the underlying data.
no setter
alloc Pointer<NativeFunction<Pointer<Void> Function(Pointer<Void> ctx, Size len, Uint8 alignment, UintPtr ret_addr)>>
Return a pointer to len bytes with specified alignment, or return NULL indicating the allocation failed.
getter/setter pair
free Pointer<NativeFunction<Void Function(Pointer<Void> ctx, Pointer<Void> memory, Size memory_len, Uint8 alignment, UintPtr ret_addr)>>
Free and invalidate a region of memory.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
remap Pointer<NativeFunction<Pointer<Void> Function(Pointer<Void> ctx, Pointer<Void> memory, Size memory_len, Uint8 alignment, Size new_len, UintPtr ret_addr)>>
Attempt to expand or shrink memory, allowing relocation.
getter/setter pair
resize Pointer<NativeFunction<Bool Function(Pointer<Void> ctx, Pointer<Void> memory, Size memory_len, Uint8 alignment, Size new_len, UintPtr ret_addr)>>
Attempt to expand or shrink memory in place.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited