WasmMemory.create constructor

WasmMemory.create(
  1. WasmStore store, {
  2. required int initial,
  3. int? maximum,
})

Creates a new memory in store.

Implementation

factory WasmMemory.create(
  WasmStore store, {
  required int initial,
  int? maximum,
}) => scoped((arena) {
  final limits = arena<c.wasm_limits_t>()
    ..ref.min = initial
    ..ref.max = maximum ?? c.wasm_limits_max_default;
  final type = c.wasm_memorytype_new(limits);
  try {
    final out = arena<c.wasmtime_memory_t>();
    throwIfError(c.wasmtime_memory_new(store.context, type, out));
    return WasmMemory._(store, readMemoryHandle(out.ref));
  } finally {
    c.wasm_memorytype_delete(type);
  }
});