Skip to content

Is memory copy involved when sending Uint8List from Dart to Rust? #52

Answered by shekohex
temeddix asked this question in Q&A
Discussion options

You must be logged in to vote

If I understand you correctly, you mean when you send a Uint8List from Dart to Rust, is there any memcopy involved? The answer depends on the implementation really, the DartVM and your code.

allo-isolate is very low-level when it comes to send data from Dart to Rust, especially on Objects/Classes/Structs ..etc.
Rust expects the things that gets sent to its functions to be C-ABI compatible; Hence when sending a Uint8List to Rust you need to send two things (ptr, len) so Rust can read the data by using std::slice::from_raw_parts.

The way you get a pointer from the Uint8List is a bit tricky, since afaik, there is no direct way to do so, since this data is managed by the GC. The only way that…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by shekohex
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #49 on October 05, 2023 14:46.