Skip to content

zero copy vec of types #647

Answered by fzyzcjy
Roms1383 asked this question in Q&A
Aug 23, 2022 · 2 comments · 8 replies
Discussion options

You must be logged in to vote

ZeroCopyBuffer relys on the underlying Dart C api: https://github.com/sunshine-protocol/allo-isolate/blob/913b17dfb34b3a63bbbf4ddb282e97b8340e3e0e/src/ffi.rs#L56 i.e. https://github.com/dart-lang/sdk/blob/main/runtime/include/dart_native_api.h

Thus, given that Dart only exposes a C api that represents u8/i8/... arrays, we seem to have no other approaches at the first glance.

However there do seem to exist an approach

you may use "wrappers" around raw bytes. For example, say I have struct S {a: u8, b: u8} and suppose each field align to 4 bytes (only for simplicity!). Then we can do the following to zero-copy a Vec<S> to Dart:

  1. We are given a Vec<S>
  2. Use bytemuck or other crate, to convert to

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
8 replies
@Roms1383
Comment options

@Roms1383
Comment options

@fzyzcjy
Comment options

@Roms1383
Comment options

@fzyzcjy
Comment options

Answer selected by Roms1383
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
3 participants