I'm doing it in this way:
Pointer<Uint8> _byteDataToPointer(ByteData byteData) {
final uint8List = byteData.buffer.asUint8List();
final length = uint8List.lengthInBytes;
final result = allocate<Uint8>(count: length);
for (var i = 0; i < length; ++i) {
result[i] = uint8List[i];
}
return result;
}
Is there a more efficient way like JNIEnv::GetByteArrayRegion in JNI?
Thank you very much!
This is always going to involve a copy, so is there something more efficient than your for loop? Maybe.
After allocating your Uint8Pointer
use asTypedList
to convert it to a Uint8List
. Now you have access to its copy primitive like setAll
and setRange
to copy from the source to the destination.
What's the original source of the ByteData
? If you knew the size in advance, could you allocate the Uint8Pointer first, convert to typed data and then read directly into that?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.