-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add ability to trasnsfer TypedData to ffi #60170
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
Comments
For short running FFI calls ( https://api.dart.dev/stable/latest/dart-ffi/Int32ListAddress/address.html (Leaf calls prevent the Dart GC from running, so the typed data will not move during a leaf call. It blocks the GC, and you cannot call back into Dart in leaf calls.) If you cannot make it a leaf call and you need to copy you can take advantage of memcopy by using https://api.dart.dev/stable/latest/dart-ffi/Uint32Pointer/asTypedList.html https://api.dart.dev/stable/latest/dart-core/List/setRange.html |
@MohiuddinM could you give a bit more details on what you are trying to achieve? Where does @dcharkes we have a bunch of open issues around the same topic (efficient
Tangentially related: |
@mraleph I am trying to process video feed using AI, I get video feed using OpenCV (ffi), process it in Dart, and then pass it to tensorflow (ffi), and then get the result out back to Dart. The overhead for the transfer is 100ms more as compared to keeping the whole thing in C. |
Would it be possible to do this with only |
Thanks @dcharkes I will try your solution. |
@dcharkes Thanks for the help, processing everything in the native memory solves the problem. |
Right now, we have to allocate a buffer using malloc, and then copy TypedData to the buffer element by element. This adds a lot of overhead, and makes the ffi calls slow for larger buffers. So it will be great if we can get a pointer to TypedData, and use that in ffi calls.
We can have a version of malloc that takes a TypedData, instead of size, and then allocates the TypedData buffer in native memory. Then we can add a method to TypedData called
.toNative()
on top of that.The text was updated successfully, but these errors were encountered: