What would be the memory size/space occupied in bits/bytes by array as follows.
final String[] objects_user1={"1","10","100","1000","10000"};
-
2I hope this isn't for a live test or interview....Michael Todd– Michael Todd2010年11月30日 17:09:12 +00:00Commented Nov 30, 2010 at 17:09
-
Cant be for an interview since you dont need to know reallywillcodejavaforfood– willcodejavaforfood2010年11月30日 17:10:15 +00:00Commented Nov 30, 2010 at 17:10
-
2Unless you're talking about a specific JVM implementation on a specific architecture, you can really only come up with an estimate. There is nothing in the specs that say precisely how much storage anything will take in Java.Laurence Gonsalves– Laurence Gonsalves2010年11月30日 17:13:01 +00:00Commented Nov 30, 2010 at 17:13
-
Also you can try this.tpv– tpv2010年11月30日 17:14:44 +00:00Commented Nov 30, 2010 at 17:14
-
I am trying to calculate the performance of a device and running the code on it. I want to create objects of different size and then retrieve them, thus calculate the throughput.David Prun– David Prun2010年11月30日 17:32:58 +00:00Commented Nov 30, 2010 at 17:32
4 Answers 4
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).
1 Comment
Did you try to Google it? Here is the first result of my Google search.
Comments
Impossible to say, since its an implementation detail of the JRE you're using.
Comments
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.