In Java does anyone use short or byte?

前端 未结 11 888
挽巷
挽巷 2020-12-14 15:44

Apart from using (byte[]) in streaming I don\'t really see byte and short used much. On the other hand I have seen long used where the actual value is |100| and byte would b

11条回答
  •  無奈伤痛
    2020-12-14 15:57

    In a 64-bit processor, the registers are all 64-bit so if your local variable is assigned to a register and is a boolean, byte, short, char, int, float, double or long it doesn't use memory and doesn't save any resources. Objects are 8-byte aligned so they always take up a multiple of 8-byte in memory. This means Boolean, Byte, Short, Character, Integer, Long , Float and Double, AtomicBoolean, AtomicInteger, AtomicLong, AtomicReference all use the same amount of memory.

    As has been noted, short types are used for arrays and reading/writing data formats. Even then short is not used very often IMHO.

    Its also worth noting that a GB cost about £80 in a server, so a MB is about 8 pence and a KB is about 0.008 pence. The difference between byte and long is about 0.00006 pence. Your time is worth more than that. esp if you ever have a bug which resulted from having a data type which was too small.

提交回复
热议问题