Passing big arrays efficiently between Flutter (dart) and its FFI (C/C++)?

Issue

We are developing a “image editor” app using Flutter. Thus, we need to (1) show images on the UI, and (2) manipulate images using some algorithms in C/C++.

Flutter does have a FFI between dart and c/c++, but I do not know how to pass big arrays like images (e.g. can be megabytes) efficiently?

Thanks very much!

Solution

After experiments, now I have some code (in the production code!) passing around array of 20MB size between C and Dart. It only takes several milliseconds (just a rough estimation, but surely it does not take seconds).

Thus, my answer to my question is: Just do it. Memory copies seems to be quite cheap, and do not worry about it 🙂

Answered By – ch271828n

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.