Exchange data via WebAssembly linear memory

[![wasmtime-badge]][wasmtime] [![cat-wasm-badge]][cat-wasm]

WebAssembly modules communicate with their host through linear memory — a flat, byte-addressable array that both sides can read and write. This recipe writes two i32 values into the WASM module's memory, calls a function that adds them, and reads the result back from the return value.

get_memory retrieves the module's exported memory object. data_mut gives a mutable byte slice covering the entire linear memory so the host can write inputs before the call.

{{#include ../../crates/wasm/src/bin/linear_memory.rs::33}}

Run it:

cargo run --manifest-path crates/wasm/Cargo.toml --bin linear_memory
# 17 + 25 = 42

{{#include ../links.md}}