java short,integer,long performance

前端 未结 6 698
我在风中等你
我在风中等你 2021-01-01 23:27

I read that JVM stores internally short, integer and long as 4 bytes. I read it from an article from the year 2000, so I don\'t know how true it is now.

For the newe

6条回答
  •  长发绾君心
    2021-01-02 00:13

    It's an implementation detail, but it's still true that for performance reasons, most JVMs will use a full word (or more) for each variable, since CPUs access memory in word units. If the JVM stored the variables in sub-word units and locations, it would actually be slower.

    This means that a 32bit JVM will use 4 bytes for short (and even boolean) while a 64bit JVM will use 8 bytes. However, the same is not true for array elements.

提交回复
热议问题