@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 builtin = @import("builtin");
const expect = std.testing.expect;
test "@wasmMemoryGrow" {
if (builtin.arch != .wasm32) return error.SkipZigTest;
var prev = @wasmMemorySize(0);
expect(prev == @wasmMemoryGrow(0, 1));
expect(prev + 1 == @wasmMemorySize(0));
}
``` ```
$ zig test test.zig
1/1 test "@wasmMemoryGrow"... SKIP
0 passed; 1 skipped.
See also:
- @wasmMemorySize
