Performance comparison of array of arrays vs multidimensional arrays

后端 未结 4 1771
Happy的楠姐
Happy的楠姐 2020-12-18 03:18

When I was using C++ in college, I was told to use multidimensional arrays (hereby MDA) whenever possible, since it exhibits better memory locality since it\'s allocated in

4条回答
  •  佛祖请我去吃肉
    2020-12-18 04:00

    I would not waste the effort to use a 1D array as a multidim array in Java because there is no syntax to help. Of course one could define functions (methods) to hide the work for you, but you just end up with a function call instead of following a pointer when using an array of arrays. Even if the compiler/interpreter speeds this up for you, I still don't think it is worth the effort. In addition you can run into complications when trying to use code that expects 2D (or N-Dim) arrays that expect as arrays of arrays. I'm sure most general code out there will be written for arrays like this in Java. Also one can cheaply reassign rows (or columns if you decide to think like that).

    If you know that this multidim array is a bottleneck, you may disregard what I said and see if manually optimizing helps.

提交回复
热议问题