且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

3d - > 1D数组索引

更新时间:2023-02-26 14:48:56

你写的是等价于这样做的指针运算:

  T x [D] [H] W]。 

x [i] [j] [k]; //指针运算在这里

显然,根据你如何订购 D H W (或 i j k ),计算将不同。


in C++, what is the indexing value for a W * H * D sized 3D array?

for a particular i, j, k is this the correct indexing:

i*W*H+j*W+k

What you have written is equivalent to the pointer arithmetic that this would do:

T x[D][H][W];

x[i][j][k];  // Pointer arithmetic done here

Obviously, depending on how you order D, H and W (or i, j, k), the calculation will differ.