IssueRaiser

Zero-copy pass ArrayBuffer from JS-land to WebAssembly-land

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: 1. allocate a new WebAssembly.Memory (or whatever allocation strategy you use) 2. copy the contents of ArrayBuffer with the message to the ArrayBuffer of the WebAssembly.Memory 3. call into C++ and use the copied memory as char * 4. 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?

Posted by ghost on Dec 5, 2017, 7:59 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,500 issues0 comments

github (Other)

Zero-copy pass ArrayBuffer from JS-land to WebAssembly-land

ghostDec 5, 2017, 7:59 PM

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: 1. allocate a new WebAssembly.Memory (or whatever allocation strategy you use) 2. copy the contents of ArrayBuffer with the message to the ArrayBuffer of the WebAssembly.Memory 3. call into C++ and use the copied memory as char * 4. 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?

Comments (0)

No comments yet. Start the discussion.

Comment on this issue