-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
napi_create_arraybuffer problem #128
Comments
Actually this is a limitation (https://emnapi-docs.vercel.app/reference/list.html#arraybuffer-related), unlike in native, wasm code can not directly access V8 API so there is no way to "link" the memory of ArrayBuffer (managed by V8) to a |
Is there any way possible to malloc from the wasm heap the necessary memory and take a view as the ArrayBuffer? |
emnapi/packages/emnapi/include/node/emnapi.h Lines 61 to 67 in 416fa06
|
Fair enough. I was hoping there was a way to simulate the ArrayBuffer since it would be easier to integrate emnapi into another external project without modifying their code to do the memory synchronization. I'll work around emnapi's limitation instead. Thanks! |
I have also been wondering if there is a way to simulate an external ArrayBuffer, but the key problem is that the JS engine's memory and wasm memory are isolated from each other. What I can think of is to use |
I'm attempting to call napi_create_arraybuffer from https://github.com/nodejs/node-addon-api/blob/294a43f8c6a4c79b3295a8f1b83d4782d44cfe74/napi-inl.h#L1998.
However, writing to the memory pointed to by the output data void pointer does not correctly update the state of the arraybuffer in javascript. I was able to successfully use napi_create_external_arraybuffer from emnapi by passing in the desired buffer during ArrayBuffer construction rather than mutating the allocated buffer after construction.
Any ideas what might be going wrong? I didn't really understand the logic in emnapiExternalMemory.getArrayBufferPointer. It appears to be correct if you want to read the buffer, but since it makes a copy, I don't see how it could properly provide write access to the caller.
According to the napi docs https://nodejs.org/api/n-api.html#napi_create_arraybuffer:
Thanks!
The text was updated successfully, but these errors were encountered: