Is there any advantages to use `Short` instead of ...
# getting-started
j
Is there any advantages to use
Short
instead of
Int
? When writing this code:
Copy code
val foo: Short = 36
I get the following JVM bytecode:
Copy code
BIPUSH 36
ISTORE 0
But bipush stores integers, so is there any advantages to use
Short
? Maybe with the native target?
m
It's advantageous when you're running on 16 bit hardware 😛
😂 1
e
JVM values on the stack are always int- or long-sized
the smaller boolean byte and short types are only smaller than int when in a field or array
on native, registers are similarly going to be 32- or 64-bit and stack alignment will cause most values to be padded when spilled, so the story is pretty similar
c
To complete what has been said before: smaller-than-int types mainly exist for storage/network reasons. They are not meant for computation, as computers usually work with 32+bits units anyway.
j
Should have thought of that! Thank you all 🙏