开发者

Array size in Java

开发者 https://www.devze.com 2023-01-28 17:35 出处:网络
What would be the memory size/space 开发者_Go百科occupied in bits/bytes by array as follows. final String[] objects_user1={\"1\",\"10\",\"100\",\"1000\",\"10000\"};

What would be the memory size/space 开发者_Go百科occupied in bits/bytes by array as follows.

final String[] objects_user1={"1","10","100","1000","10000"};


ROUGH ESTIMATE: 12 bytes for array header, 4x5 bytes for the pointers (8x5 if you're on a 64 bit jvm), each string has 3 ints (+3x4 bytes), and an array of chars (+12 bytes for header + length of the string x2, because it's char).


Did you try to Google it? Here is the first result of my Google search.


Impossible to say, since its an implementation detail of the JRE you're using.


You can get an approximate answer by querying available heap space before & after the memory allocation. Run it a number of times & compute the average, & it will be pretty close to the right answer. But again, the answer is only valid for the specific JVM it's run on.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号