Is it really faster to calculate the index in a one dimension array than to look it up directly in a 3-dimensional one?
Yes. First it’s industry standard for some reason.
Second
int something = array[l * j + k*j2 + j3];
translates into
mov ebx, array
mov edx, l
mov eax, j
mul edx
add ebx, eax
mov edx, j2
mov eax, k
mul edx
add ebx, eax
mov edx, j3
add ebx, edx
possibly do array boundary checks
mov eax, [ebx]
int something = array[j][j2][j3];
converts to this
mov eax, array
mov ebx, j
add eax, ebx
mov eax, [eax]
mov ebx, j2
add eax, ebx
mov eax, [eax]
mov ebx, j3
add eax, ebx
mov eax, [eax]
In optimal case.
or into this
mov eax, array
mov ebx, j
add eax, ebx
possibly do array boundary checks
mov eax, [eax]
mov ebx, j2
add eax, ebx
possibly do array boundary checks
mov eax, [eax]
add eax, j3
possibly do array boundary checks
mov eax, [eax]
or into this
call retrieveArray, array (boundary checks might be in this inlineable function)
mov ebx, j
add eax, ebx
call retrieveArray, eax
mov ebx, j2
add eax, ebx
call retrieveArray, eax
mov ebx, j3
add eax, ebx
mov eax, [eax]
Another differences are
One random memory access vs three random memory accesses.
Has higher pointer overhead. Array of refferences is 24 bytes + a * 8 bytes on 64 bit computer. (12 + a * 4 on 32 bit)
BTW if this[quote]new Tile[128][128][10];
[/quote]
was supposed to hold 10 different tiles, it was done wrongly
Tile ti = new Tile[10]
ti[0] = new Tile(128, 128);
Would work much better.