java - better to use one 3d array or two 2d? -


if want store 2 values in 2d array, better (memory , speed-wise) use 1 3d array store values? or 2 2d arrays? eg:

int[][][] array = new int[rows][cols][data];  for(int = 0; < rows; i++)     for(int j = 0; j < cols; j++)     {         array[i][j][0] = value1;         array[i][j][1] = value2;     } 

or

int[][] array1 = new int[rows][cols]; int[][] array2 = new int[rows][cols];  for(int = 0; < rows; i++)     for(int j = 0; j < cols; j++)     {         array1[i][j] = value1;         array2[i][j] = value2;     } 

or wouldnt matter in terms of performance?

they arent massive arrays using, hundred hundred @ probably.. if scale up, best use?

or, if performance wont affected @ all, considered best coding practice?

edit: related java project, more interested in general; if there different languages make difference depending on method used, information useful future reference..

not knowing want achieve, need place object relevant data in matrix (provided best description of problem area). mean.

class measurepoint {   int temperature;  // example   int windspeed;    measurepoint(int a, int b) {     temperature = a;     windspeed = b;   } }  measurepoint[][] map = new measurepoint[rows][cols];  for(int = 0; < rows; i++) {     for(int j = 0; j < cols; j++) {       map[i][j] = new measurepoint(value1, value2);     } } 

java object oriented. take advantage of modelling tools have @ disposal. if want traverse memory, off assembly.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -