Skip to content

proposal: syscall/js: allow passing a slice of bytes directly to JavaScript #46473

Open
@BenLubar

Description

@BenLubar

In the same way that you can pass a pointer to an element of a byte slice to a function via CGo without copying it, assuming the function you're calling doesn't hold on to the pointer after it returns, it should be possible to call JavaScript functions with a Uint8Array that points directly to Go memory.

This could be used to make calls to functions like WebGLRenderingContext.bufferData more efficient, as the data wouldn't need to be copied twice (once from Go to JavaScript and then again by the browser).

The same caveats as passing a *byte to CGo would apply: if the function you're calling holds on to the pointer after it returns, the pointer will probably eventually point to something else.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions