Struct TVMFFICustomAllocator

Struct TVMFFICustomAllocator#

Struct Documentation#

struct TVMFFICustomAllocator#

Allocator interface for TVM FFI object storage.

A frontend may register this allocator with TVMFFISetCustomAllocator to control allocations of subsequently created TVMFFIObject instances. This allows the frontend to prepend private metadata and coordinate object storage reclamation with language-specific state.

Every returned object body must be immediately preceded by an initialized TVMFFIObjectAllocHeader. An allocator may place additional private metadata before that header.

Note

The registered allocator and its context must remain valid for the lifetime of the process.

Note

The allocation callback may be invoked concurrently.

Public Members

void *(*allocate)(size_t size, size_t alignment, int32_t type_index, void *context)#

Allocate uninitialized storage for a TVM FFI object body.

The returned pointer must be immediately preceded by an initialized TVMFFIObjectAllocHeader whose delete_space callback is responsible for eventually reclaiming the complete allocator-owned allocation.

On failure, the callback must report the error through TVMFFIErrorSetRaised before returning NULL.

Note

The returned storage is uninitialized: the caller is responsible for zero-initializing or constructing the object body. Only the preceding TVMFFIObjectAllocHeader is guaranteed to be initialized on return.

Param size:

Size of the object body in bytes, excluding the preceding TVMFFIObjectAllocHeader and any allocator-private metadata.

Param alignment:

Required alignment of the returned object body.

Param type_index:

Runtime type index of the object being allocated.

Param context:

The allocator-defined context stored in this entry.

Return:

An aligned pointer to the object body, or NULL on failure.

void *context#

Opaque allocator-defined context passed unchanged to allocate.

The TVM FFI runtime neither interprets nor owns this pointer. It may be NULL; otherwise, the referenced state must remain valid for the lifetime of the registered allocator.