Skip to content

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

Open
@ghost

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:

  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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions