Rust/wasm32 managing outside-of-wasm32 mem

In my current understanding:

  1. Rust/wasm32 is limited to either 2GB or 4GB of total heap space.

  2. JS running in the browser is not limited to 4GB of total memory.

Question: In Rust, is there a crate/api for:

  1. allocating space inside the browser/JS runtime, but outside of the wasm32 ?

  2. easy API for copying sections of memory between (wasm32 heap, these 'blob' objects)

Using the js-sys crate you can create a new Uint8Array (or Float32Array or whatever floats you boat) which will live on the JavaScript heap.

From there, you can use subarray() it to access sections of that array in the same way we might do &slice[start..end] in Rust. The to_vec(), copy_from(), and copy_to() methods can be used for efficiently copying bytes to/from the Uint8Array.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.