Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypedArray / Memory<T> marshalling fails in Electron due to disabled external buffers #384

Closed
jasongin opened this issue Sep 30, 2024 · 2 comments

Comments

@jasongin
Copy link
Member

jasongin commented Sep 30, 2024

I'm creating this issue to continue the discussion from #15 (comment)

Attempting to work with JS TypedArrays from C# may result in an error from Electron's flavor of Node:

External buffers are not allowed: Error in CreateExternalArrayBuffer at D:\a\1\s\src\NodeApi\JSValue.cs:264

More information about the limitation is at electron/electron#35801. This appears to be quite a controversial issue, but the Electron team seems to believe the limitation is necessary for security.

As a workaround, node-api-dotnet probably will need to handle the new napi_no_external_buffers_allowed status code and fall back to copying the memory instead of using external buffers. That's very unfortunate since it can have a major performance impact in some scenarios, and doesn't have the same semantics as shared memory.

@jasongin jasongin self-assigned this Sep 30, 2024
@jasongin jasongin added this to the Version 1.0 milestone Sep 30, 2024
@jasongin jasongin changed the title TypedArray / Memory<T> marshalling fails in Electron due to disabled eternal buffers TypedArray / Memory<T> marshalling fails in Electron due to disabled external buffers Sep 30, 2024
@jasongin
Copy link
Member Author

Duplicate of #383

@jasongin jasongin marked this as a duplicate of #383 Sep 30, 2024
@Hiwen
Copy link

Hiwen commented Oct 1, 2024

I think this discussion is very necessary, even if we copy the memory once and convert memory directly to a typed array, theoretically we can also achieve better performance.
I haven't yet grasped the technical details of using the Node API with C#. So I have no idea how to test this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants