When working with byte streams, do you think I get...
# android
l
When working with byte streams, do you think I get any benefit of working with
Byte/UByte
(unsigned types partial stable since v1.5) instead of
Int
? I deal most of the time with values in the range of 0-255. I'm also thinking about the architecture of the cpu (cpu natively works better with
Int
while there might be extra steps to convert from
Byte
to
Int
???) but tbh, I'm not so deep in this topic. This question might be a no brainer but anyway I'm curious about the pros and cons if there are any.
e
Byte/UByte at the interface level is useful for expressing intention
but all arithmetic promotes to Int- or Long-sized values
e.g.
operator fun Byte.plus(Byte): Int
,
operator fun UByte.plus(UByte): UInt
in practice, there are no extra steps to convert from Byte to Int; instead, there are extra steps to ensure that the Int-sized registers and memory used to are masked to a Byte-sized value
l
Sounds good, then I will continue working with Byte/UByte. Thanks for the insights