0

What would be the memory size/space occupied in bits/bytes by array as follows.

final String[] objects_user1={"1","10","100","1000","10000"};
EboMike
77.9k15 gold badges172 silver badges171 bronze badges
asked Nov 30, 2010 at 17:06
6
  • 2
    I hope this isn't for a live test or interview.... Commented Nov 30, 2010 at 17:09
  • Cant be for an interview since you dont need to know really Commented Nov 30, 2010 at 17:10
  • 2
    Unless 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. Commented Nov 30, 2010 at 17:13
  • Also you can try this. Commented 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. Commented Nov 30, 2010 at 17:32

4 Answers 4

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).

answered Nov 30, 2010 at 17:14

1 Comment

Yeah, I wonder that too. I think if peole are going to downvote, they should at least tell you why. I'll give you an upvote to cancel it out. :-)
0

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

answered Nov 30, 2010 at 17:09

Comments

0

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

answered Nov 30, 2010 at 17:17

Comments

0

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.

answered Dec 1, 2010 at 16:19

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.