@wasmMemoryGrow

@wasmMemoryGrow

@wasmMemoryGrow(index: u32, delta: u32) i32

This function increases the size of the Wasm memory identified by index by delta in units of unsigned number of Wasm pages. Note that each Wasm page is 64KB in size. On success, returns previous memory size; on failure, if the allocation fails, returns -1.

This function is a low level intrinsic with no safety mechanisms usually useful for allocator designers targeting Wasm. So unless you are writing a new allocator from scratch, you should use something like @import("std").heap.WasmPageAllocator.

test.zig

const std = @import("std");
const native_arch = @import("builtin").target.cpu.arch;
const expect = std.testing.expect;

test "@wasmMemoryGrow" {
    if (native_arch != .wasm32) return error.SkipZigTest;

    var prev = @wasmMemorySize(0);
    try expect(prev == @wasmMemoryGrow(0, 1));
    try expect(prev + 1 == @wasmMemorySize(0));
}
``` ```
$ zig test test.zig
Test [1/1] test "@wasmMemoryGrow"...
Test [2/1]
test "@wasmMemoryGrow"... SKIP

0 passed; 1 skipped; 0 failed.

See also:

  • @wasmMemorySize