Hello,
I am using this piece of code for allocating 3D array in memory by my dimensions HEIGHT, WIDTH, DEPTH which are variables.
p2DArray = new double**[HEIGHT];
for (int i = 0; i < HEIGHT; ++i) {
p2DArray[i] = new double*[WIDTH];
for (int j = 0; j < WIDTH; ++j)
p2DArray[i][j] = new double[DEPTH];
}
My problem is this: When i have for example HEIGHT = 512, WIDTH = 512 and DEPTH = 2 my 3D allocated array has right dimension in HEIGHT and WIDTH but DEPTH dimensions are not 2, but its larger.
For example when I want to read p2DArray[511][511][845646] it doesnt say me, that I am out of dimensions (with [845646] in DEPTH), but it will give me random number value. When I want to read on position for example p2DArray[518][511][0] it will say me, that I am out of dimension because of HEIGHT size.
Could you please tell me, why this piece of code allocates 3D array right in HEIGHT and WIDTH dimension, but false in DEPTH (it allocates a lot of bigger in DEPT dimension, than I would like)?
THANKS FOR ANY HELP!