buffer property

Uint8List get buffer

The memory contents, as a view onto the native memory.

Like WebAssembly.Memory.prototype.buffer in JavaScript, the view becomes invalid when the memory grows: ask for buffer again afterwards.

For a 64 bit or shared memory this view is not available.

Implementation

Uint8List get buffer => scoped((arena) {
  final native = _native(arena);
  final data = c.wasmtime_memory_data(store.context, native);
  if (data == ffi.nullptr) {
    throw StateError(
      'This memory has no linear byte buffer (it is shared or 64 bit).',
    );
  }
  return data.asTypedList(c.wasmtime_memory_data_size(store.context, native));
});