Java: Multi-dimensional array vs. one-dimensional

后端 未结 4 750
粉色の甜心
粉色の甜心 2020-11-29 00:47

For example:

  • a) int [x][y][z]

    vs

  • b) int[x*y*z]

Initi

4条回答
  •  生来不讨喜
    2020-11-29 01:09

    If you choose the latter route then you're going to have to perform arithmetic for every single array access. That's going to be a pain and error prone (unless you wrap it in a class providing this functionality).

    I don't believe that there's any (significant) optimisation in choosing your flat array (especially given the arithmetic taken to index into it). As always with optimisations, you would need to perform some measurements and determine if it's really worth it.

提交回复
热议问题