java array memory usage
807600Sep 13 2007 — edited Sep 16 2007I have a java program which unfortunately uses a large array of integers [4,100,000][2][2][5]. It declares this at program load and fills it with values shortly after. Just doing a bit of maths on this I calculate it to be 4 (32 bit int) * 4,100,000 * 2 * 2 * 5 = 328,000,000 or 328 mb.
I understand the language will use some extra memory for pointers and what ever else but I set the jvm to have 512mb of space and it uses all of it and runs into the out of memory error (if I write the values to a file instead it only uses about 6mb of memory). I tried it at 768mb (bearing in mind the computer only has 1GB) and it just seemed to be trying to declare memory all the time not doing any processing. I would use the file output but I need to do a recursive search over all the array so it would be very slow unless I have all data in memory.
Is it common to have memory usage of somewhere around double what I calculated to be the array memory requirement? surely not