-
-
Notifications
You must be signed in to change notification settings - Fork 141
convert java.nio.ByteBuffer to ArrayBuffer without data copy #365
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
Conversation
💚 |
looks good 👍 |
src/src/com/tns/Platform.java
Outdated
} | ||
|
||
directBufferFactory = new DirectBufferFactory(logger); | ||
directBufferFactory.startListener(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this initialize upon demand? I mean why starting a new thread if we are not going to use it?
👍 |
💚 |
I am not sure I understand your concerns. JavaScript typed arrays are designed to use shared ArrayBuffer. They just represent different view for the underlying ArrayBuffer.
I am not sure this is supported by V8. Also, this will introduce unusual way for creating typed arrays. JavaScript provides a standard mechanism so I prefer to keep it that way.
This is another feature. This PR is focused on exposing Java memory to V8. |
from SDK: "MappedByteBuffer is a special kind of direct ByteBuffer which maps a region of file to memory."
If I create a view of already existing ArrayBuffer it is not associated with the backing ByteBuffer and the memory will be free'd at some point under my feet while I am still using my view. Or maybe I am wrong here if v8 is keeping the original reference alive.
Talking about the third ctor overload with parameter "object" https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
I think we should handle both in this implementation. Also currently this PR allows only buffers created using our own method "public ByteBuffer create(int capacity)" to work correctly so this is useful only to specific native libraries which know and call this method to allocate buffers.This handicaps the offering. I think we can provide more generic approach and work with any library that provides direct ByteBuffers to JS code. |
💔 |
💔 |
💚 |
Create a simplified version #379. Closing this. |
related to #65