Skip to content

Details about ZeroCopyBuffer #1221

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

You must be logged in to vote

Can I make the function's return type to be something like ZeroCopyBuffer? Would this work as intended, without copying the fields of MyCustomStruct?

Yes and no.

ZeroCopyBuffer is implemented by Dart primitives, which only support a flat byte array.

But, if you generate some Dart code like:

class Apple {
  final Uint8List bytes;
  int get aaa => bytes[0] * 256 + bytes[1];
  int get bbb => bytes[2];
}

Then I guess it should work.

I wonder if there would be some data type like Arc, that can be used both in Dart and Rust, without any copying.

I am worried that this may violate the memory model of Rust very easily. For example, you can modify the bytes in Dart and Rust at the same time.

H…

Replies: 2 comments 1 reply

Comment options

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

You must be logged in to vote
1 reply
@fzyzcjy
Comment options

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