That depends on the usage scenario of your code. Creating 3-dimensional array is very expensive in terms of resources (memory) so you should only use it when you are creating voxel structures or you know that you will need to fill all of the points in the space x*y*z
. For this case the code
int spacial[][][] = new int[1024][768][100];
spacial[100][200][10] = 1; // 1 set that a point is present
makes more sense to use. It is also useful if you want to quickly find whether certain spacial coordinate exists.
For other cases you can create structure
struct Coord
{
int x, y, z
}
and then create array of instances of this structure instead. This gives you more memory efficiency as you do not have to have every single coordinate represented (even if it isn't there). You can still use algorithms to search efficiently using octrees for searching but they are more complex to implement.
You can find more information about octrees in my answer to another question.