Skip to main content

Saving Data

Writing Data to Disk#

WASM-4 supports saving up to 1024 raw bytes of data using diskw(). It takes a source data pointer along with a byte length.

For example, to write a 32 bit integer with the value 1337 to disk:

// First we need to store the value somewhere in memory to get a pointerconst ptr = memory.data(sizeof<i32>());store<i32>(ptr, 1337);
w4.diskw(ptr, sizeof<i32>());

Reading Data from Disk#

Reading is similar, using diskr(). It takes a destination pointer along with a byte length.

For example, to read a 32 bit integer from disk:

const ptr = memory.data(sizeof<i32>());w4.diskr(ptr, sizeof<i32>());
const gameData = load<i32>(ptr);