Zero-copy pass ArrayBuffer from JS-land to WebAssembly-land · Issue #1162 · WebAssembly/design (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Description
Hey,
From reading about the WebAssembly.Memory there really is no way to pass an ArrayBuffer zero-copy to C++ from JS.
Example:
Let's say a WebSocket in the browser triggers the onmessage with an ArrayBuffer of the message data. Now I want to read this data in C++. From all solutions I've seen you really need to:
- allocate a new WebAssembly.Memory (or whatever allocation strategy you use)
- copy the contents of ArrayBuffer with the message to the ArrayBuffer of the WebAssembly.Memory
- call into C++ and use the copied memory as char *
- free the WebAssembly.Memory
Imagine having a constructor like new WebAssembly.Memory(ArrayBuffer) so that you could skip all steps except for step 3.
Did I get something wrong or is this not supported?