Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast copy ByteBuffer into ByteBuffer in Dart

How do I perform a fast copy of the bytes of a ByteBuffer into another larger ByteBuffer (at non-zero offset) in Dart?

There are slow ways to do this. One is to cast each to a Uint8List and copy over one index at a time. Another is to cast into each into a Uint8List, get an iterator for the first, and call setRange() on the second.

I'm thinking there ought to be a more direct way that asks the Dart API to speedily copy a byte sequence from one buffer to the other. The API can natively optimize this copy. If not, what's the fastest way to do this?

like image 748
Joe Lapp Avatar asked Nov 07 '22 11:11

Joe Lapp


1 Answers

Try this, it should be faster than copy Uint8List value by value for larger dataset.

        String url = Url.createObjectUrlFromBlob(new Blob([srcBuffer]));
        ByteBuffer dstBuffer = (await HttpRequest.request(url, responseType: 'arraybuffer')).response;
        Url.revokeObjectUrl(url);
like image 114
Ivo Skalický Avatar answered Nov 22 '22 11:11

Ivo Skalický