Does
int x;
use the same amount of memory, as
int[1][1][1][1][1] x;
?
Does
int x;
use the same amount of memory, as
int[1][1][1][1][1] x;
?
No.
this is an object int[][][][][] pointing to the object int[][][][] pointing to the object int[][][] pointing to the object int[][] pointing to the object int[] pointing to a primitive int
I have a class in which I have an
Object[][]
because there are cases in which both dimensions are used and some cases in which the second dimension is just 1
I thought this was a better solution than to kinda declare
Object a[]
and
Object b[][]
and do some ifs, because I hoped my solution would use less memory
and yea I should note that this is a performance critical class, so its should be done the best way.
You could always flatten the array (assuming you know the dimensions at creation time).
how does that work exactly ?
Object[width][height]
becomes
Object[width*height]
where an access like:
Object[i][j]
becomes
Object[i*arrayWidth+j]
ah, clever.
thanks