Zero-copy pass ArrayBuffer from JS-land to WebAssembly-land · Issue #1162 · WebAssembly/design (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

@ghost

Description

@ghost

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?