I am using dart:ffi.
I have a C function that accepts a pointer to array:
void myCFunc(const void *pointer);
I want to call it from dart, right now, I am calling it like this:
void myDartFunc(Uint8List data) {
final Pointer<UnsignedChar> dataPtr = malloc(
sizeOf<UnsignedChar>() * (data.length),
);
for (int i = 0; i < data.length; i++) {
dataPtr[i] = data[i];
}
callMyCFunc(dataPtr);
}
Which is not so optimal for long lists as it copies the array into a new array.
Is there a way to get pointer to data
without copying each element?