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

Generate adapter code for arrays and typed arrays #15

Closed
wants to merge 3 commits into from
Closed

Conversation

vmoroz
Copy link
Member

@vmoroz vmoroz commented Mar 26, 2023

jasongin Authored by jasongin on Feb 9, 2023, merged on Feb 10, 2023
Imported from jasongin/napi-dotnet repo


  • Generate adapter code for arrays: C# T[] <-> JS T[] for any T that can be converted including primitives, structs, classes, etc.
    • Unfortunately array data must be copied because it's impossible to create a C# array over external memory.
  • Add JSTypedArray<T> value type.
  • Generate adapter code for typed arrays: C# Memory<T> <-> JS TypedArrays, where T is one of the valid typed-array element types, for example Memory<int> <-> Int32Array.
    • Typed arrays can be passed back and forth without copying the data, with some careful marshalling and lifetime management -- see JSTypedArray.MemoryManager.
  • Generate TS type definitions for arrays, typed arrays, and collections.

(Runtime adapter code is not yet generated for collections; I'm planning to work on that next. Collections should be adaptable without copying, by leveraging JS Proxy objects.)

@vmoroz vmoroz closed this Mar 26, 2023
@vmoroz vmoroz deleted the pr15head branch March 26, 2023 07:03
@Hiwen
Copy link

Hiwen commented Sep 29, 2024

I Test Memory<T> to TypedArray<T> on Electron 19.1.9,That Worked fine and has amazing Performance.
But when I Test on higher Electron, such as 32.1.2, it was not worked. And reported an error:

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

I did some research,the use of External buffers has actually been officially banned.
electron/electron#35801

Does anyone know how to turn on External buffers support in the new version of Electron? Like turn it on by some command parameter or something。

@jasongin
Copy link
Member

jasongin commented Sep 30, 2024

Thanks for the comment @Hiwen, I wasn't aware of that limitation on Electron.

Let's continue discussion in #383 instead of on this old closed PR.

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

Successfully merging this pull request may close these issues.

3 participants