Hi all. I have a question that is probably simple to answer, but I don't even know where to get started (i.e. for searching old posts, Google, etc.)
I am writing a program that reads in a 3 dimensional array text file. Then x, y, and z coordinate values are assigned to each value of the 3d array. These four arrays (3d array, x, y, z) get used in quite a few functions of my program. So, I define them all as globals.
My program needs to handle 3d arrays that could potentially be larger than 512x512x512, but my program doesn't know how large until the user inputs that information. I don't really want to hard code in some generic, large number when I create the arrays.
My question is then this: Is there anyway to have these four arrays be treated as globals, but created (with the proper size) after the user enters the size of the 3d array?
This piece of code is something I've done before, but of course sphere[i][j][k] isn't a global...
Thanks in advance,
-Michael
I am writing a program that reads in a 3 dimensional array text file. Then x, y, and z coordinate values are assigned to each value of the 3d array. These four arrays (3d array, x, y, z) get used in quite a few functions of my program. So, I define them all as globals.
My program needs to handle 3d arrays that could potentially be larger than 512x512x512, but my program doesn't know how large until the user inputs that information. I don't really want to hard code in some generic, large number when I create the arrays.
My question is then this: Is there anyway to have these four arrays be treated as globals, but created (with the proper size) after the user enters the size of the 3d array?
This piece of code is something I've done before, but of course sphere[i][j][k] isn't a global...
Code:
void LoadFile() { int ***sphere = NULL; sphere = new int**[userValueX]; for (i=0; i<userValueX; i++) { sphere[i] = new int*[userValueY]; for (j=0; j<userValueY; j++) { sphere[i][j] = new int[userValueZ]; } } ... }
-Michael
Comment