Pass JS Float64Array to Rust using WASM

This approach is working great. My latest code is here, pointing at the part that allocates space for the array of floats in Rust code: https://github.com/mvolkmann/wasm-bind-demo/blob/707e7c65e516d3534648ff99cedcc161bc94aa37/src/lib.rs#L46.
Could I instead allocate the space in the JS code and get Rust to use that space? I'm thinking this might simplify the code overall if it is possible.

As I understand it, this is fundamentally not possible in the WASM model. While JavaScript can peek inside of the WASM virtual machine, WASM code cannot access the outside world. So any allocation shared between the two domains must originate from inside of WASM.

2 Likes

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.