wasmtime_externref_new function

  1. @Native<Bool Function(Pointer<wasmtime_context_t>, Pointer<Void>, Pointer<NativeFunction<Void Function(Pointer<Void>)>>, Pointer<wasmtime_externref_t>)>(ffi.Pointer<wasmtime_context_t>, ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>, ffi.Pointer<wasmtime_externref_t>)>()
bool wasmtime_externref_new(
  1. Pointer<wasmtime_context_t> context,
  2. Pointer<Void> data,
  3. Pointer<NativeFunction<Void Function(Pointer<Void>)>> finalizer,
  4. Pointer<wasmtime_externref_t> out,
)

\brief Create a new externref value.

Creates a new externref value wrapping the provided data, returning whether it was created or not.

\param context the store context to allocate this externref within \param data the host-specific data to wrap \param finalizer an optional finalizer for data \param out where to store the created value.

When the reference is reclaimed, the wrapped data is cleaned up with the provided finalizer.

If true is returned then out has been filled in and must be unrooted in the future with #wasmtime_externref_unroot. If false is returned then the host wasn't able to create more GC values at this time. Performing a GC may free up enough space to try again.

If you do not unroot the value, even if you free the corresponding Store, there will be some memory leaked, because GC roots use a separate allocation to track liveness.

Implementation

@ffi.Native<
  ffi.Bool Function(
    ffi.Pointer<wasmtime_context_t>,
    ffi.Pointer<ffi.Void>,
    ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>,
    ffi.Pointer<wasmtime_externref_t>,
  )
>()
external bool wasmtime_externref_new(
  ffi.Pointer<wasmtime_context_t> context,
  ffi.Pointer<ffi.Void> data,
  ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<ffi.Void>)>>
  finalizer,
  ffi.Pointer<wasmtime_externref_t> out,
);