Is there any performance issue while using one of below methods? Which is faster (if any)? It would be great if is there any performance tests.
Multidimmentional array:
// Using multidimmentional array:
int ****multidim_arr;
// ... initialization, etc. ...
int val = multidim_arr[a][b][c][d];
Flat array:
// Using flat array (or single array)
int *flat_arr;
// ... initialization, etc. ...
int val2 = flat_arr[a * a_lvl + b * b_lvl + c * c_lvl + d];
UPDATE:
Arrays have fixed size, but memory is allocated by malloc() function because size is known while program is working.
int arr[4][2][9][4]), then probably the multidimensional array is faster, as is carries more type information for the compiler to use in optimizations, compared to a flat array whose indices still needs to be calculated.dindex. In the former case 'a','b' and 'c' would remain cached, in the latter the whole arithmetic expression would be re-evaluated. But personally, I believe optimizer will optimize away both to the same code.****multidim_arrbut asmultidim arr[SIZE_A][SIZE_B][SIZE_C][SIZE_D]I'd stand by my previous statement. In this case I'm not really so sure.