我有一个巨大的三维数组,它代表了我的世界。它太大了,无法静态初始化:
alias Cell[128][128][128] World; // <-- The compiler points to this line
Error: index 128 overflow for static array
我尝试使用World* world
,但仍会出现上面的溢出错误。所以我现在有的是这个丑陋的混乱代码:
alias Cell[][][] World;
// ...
private World world;
// ...
world.length = WORLD_XDIM;
for (uint x = 0; x < world.length; ++x)
{
world[x].length = WORLD_YDIM;
for (uint y = 0; y < world[x].length; ++y)
{
world[x][y].length = WORLD_ZDIM;
}
}
这种方式是可行的,但它让我内心有点难过。有没有一种方法可以将 calloc 的结果转换为三维数组?我已经使用过对常规数组进行分片的方法来实现了,但三维数组让我很困惑。