c++ - More variables or one more dimension in array variable? -


i heard less dimensions better, worth change method b (that use) a?
optimal way of using array variables?

example code in c

method a: int var1[5][10][5][4]; int var2[5][10][5][4]; int var3[5][10][5][4];  method b: int var4[3][5][10][5][4]; 

i think if "better" or not depends lot on perspective, e.g. performance, readability, maintainability, consistency, , many more. there no clear answer question, , every answer might opinion based.

anyway, "mix" both approaches, having separate variables "view" slices of "many-dimension"-array. pick "best" approach respective context:

int main() {      int var4[3][5][10][5][4] = { {{{1}}}, {{{2}}}, {{{3}}} };      int (*var1)[5][10][5][4] = &var4[0];     int (*var2)[5][10][5][4] = &var4[1];     int (*var3)[5][10][5][4] = &var4[2];      return 0; } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -