In Java, on a 32 bit OS, I store 5736 int[] arrays containing 54759118 ints. If each int primitive takes 4 bytes, then I will get minimum 54759118 * 4 = 219036472 bytes ~ 220 megabytes. Since I have 5736 references to int[] objects, what will be an overhead of storing those references?
Add a comment
|
1 Answer
Each 32-bit pointer in Java allocates ~4 bytes. Hence, it will be 5736 * 4 = 22944 bytes
5 Comments
Vincent van der Weele
There are only
5736 referencesAndremoniy
@Heuster ups :)) Thank you very much, its my inattention.
Sophie Sperner
Thank you, so this will be an overhead size,
23 megabytes? Is something spent on storing say length of array, or only ints as contents and array references are stored?Andremoniy
@SophieSperner 4 bytes per an array reference. It doesn't depend on array's length. And it is only
22 kilobytes, not megabytes :)Sophie Sperner
Just a comment aside: by the link at the end they say that
int[1024] takes 4112 bytes. If you use our logic: 1024 * 4 + 4 (ref) = 4100 < 4112 consequently 12 bytes are stored for something else. Link: vanillajava.blogspot.ie/2011/07/…