I modified what rip-off presented optimized to what it needs to do, again using just a plain char* because I cannot afford any overhead.
You didn't optimise it in any way by removing the template argument. All that did is made it less generic / less useful. In fact to optimise it better you should have added more template parameters so that the size is known at compile time.
Going back to the far better code that rip-off started with and making a few tweaks...array3d.h
template<typename T, int width, int height, int depth>
Array3D() : storage(width * height * depth)
T &operator()(int x, int y, int z)
T operator()(int x, int y, int z) const
return storage[index(x, y, z)];
static int index(int x, int y, int z)
return ((x * width + y) * height) + z;
Array3D<char, 25*16, 25*16, 25*16> testWorld;
testWorld(x,y,z) = testWorld(x+16,y,z);
testWorld(x,y,z) = 1;
This does all that you want it to do. Heck, I even saved you a multiplication, although in the code I presented here, the compiler would have sorted that out.
Boost array does all this stuff for you also, so you may wish to look into that.