Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Last active February 16, 2021 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattdesl/3691e3fa39f3615aa0246f4d9828ac1d to your computer and use it in GitHub Desktop.
Save mattdesl/3691e3fa39f3615aa0246f4d9828ac1d to your computer and use it in GitHub Desktop.
// get a pointer to 16 bytes of WASM memory
const byteLength = 16;
const pointer = Module._malloc(byteLength);
// e.g. let's set all values to 0xff (255)
for (let i = 0; i < byteLength; i++) {
const idx = pointer + i;
Module.HEAPU8[idx] = 0xff;
}
// when we are done with the pointer, make sure to release it
Module._free(pointer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment