Home arrow static arrow Java Programming [Archive] - bytes of memory reserved for arrays
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - bytes of memory reserved for arrays
This topic has 3 replies on 1 page.

Posts:341
Registered: 03-06-12
bytes of memory reserved for arrays  
Aug 3, 2004 8:52 AM



 
I am not sure if I even really need to know this for programming java, but its bothering me not to know...

i know that an int stores 4 bytes of memory and a char stores 2 bytes...

is it the same for an array???
like if int a[100];
does mean we give 100 cells * 4 bytes of memory???

thanks in advance annie
 

Posts:27,518
Registered: 11/3/97
Re: bytes of memory reserved for arrays  
Aug 3, 2004 9:09 AM (reply 1 of 3)



 
Yes and no.

The data itself occupies that much, but an array is a java class. It is derived from java.lang.Object just like any other class in java. And the class itself takes a little bit more memory. So it is more likely to be like....

100*4 + 12

(Where the 12 is a 'guess'.)
 

Posts:11,200
Registered: 7/22/99
Re: bytes of memory reserved for arrays  
Aug 3, 2004 9:10 AM (reply 2 of 3)



 
Pretty much, yes. Arrays also need 4 bytes to store the length, and the memory seems to be padded so that the number of bytes used becomes a multiple of 8. Some memory is also required to save the address of the array.
http://www.javaspecialists.co.za/archive/Issue029.html
http://www.javaspecialists.co.za/archive/Issue078.html
 

Posts:341
Registered: 03-06-12
Re: bytes of memory reserved for arrays  
Aug 3, 2004 9:13 AM (reply 3 of 3)



 
thanks...i was playing around with length and length()
to see if it would set me in the right direction
thanks for the links :)
 
This topic has 3 replies on 1 page.