So I'm working on a Java program that is going to be updating a 2D array many times per second. Originally, I was copying the entirety of the array using System.arrayCopy()
, but that was clearly a bad idea since I'm only updating one row at a time. Instead I decided to just have a "pointer" to the virtual "zero" of the array. Anyway, I also want to be able to support dynamic sizing, and it occurred to me that the easiest way to do this might be to have one array that stays the same size, and then have a number that indicates the maximum length of the virtual array. I found myself thinking that could be a waste of memory though
The above information is just so someone can tell me if I'm doing something completely ridiculous.
TL;DR = if I do the following...
int[][] data = new int[2000][]; // 2000 would be the max
for(int i=0; i<10; i++) {
data[i] = new int[10];
}
...how much memory have I used in addition to the hundred ints I actually initialized? Would it just be the 4 bytes for each null reference?