Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should Uint8 in Dart/Flutter be used?

I'm working on a flutter project with lots of bytes and byte arrays. I noticed that i had access to Uint8 and Uint8List. If i understand correctly, the Uint8List will save some memory over using a normal list with bytes. However, it seems that the Uint8List only accepts regular integers. Is there any usecase for using Uint8 type? Or should i be using the int type for bytes?

like image 507
Juliantje15 Avatar asked Mar 09 '20 09:03

Juliantje15


1 Answers

Edit: The question is answered here

According to the documentation here, it accepts integers and then truncates those to the lower eight bits. This means you can effectively store four list entries in a standard 32 bit integer. When retrieving an integer, the integer is most likely prepended by the amount of bytes a reqular int uses.

like image 187
Roel van Endhoven Avatar answered Nov 12 '22 19:11

Roel van Endhoven