Original Post
Hi, I'm fairly new to c++, though I've used C a but, and am wondering what the best way would be to go about managing large amounts of data. Like, I may need an integer array thats 3D, and is 200x200x200, or even a lot larger. Back in C you couldnt just define the array without mallocing it. Heres how I was allocating it in regular C, but in 2D: Thats from Numerical Recipes in C For 3D in C, i was just using a 1D array that was representitive of 3D. But this new thing I cannot use that, I dont want to have to calculate the 3D array indices from the 1D location. Is there a 3D array class I can use that makes the best use of memory allocation?
int **imatrix(long nrl, long nrh, long ncl, long nch)
/* allocate a int matrix with subscript range m[nr1..nrh][ncl..nch] */
{
long i, nrow=nrh-nrl+1, ncol=nch-ncl+1;
int **m;
/* allocate pointers to rows */
m=(int **) malloc((size_t)((nrow+NR_END)*sizeof(int*)));
if (!m) fprintf(stderr, "allocation failure 1 in matrix()");
m += NR_END;
m -=nrl;
/* allocate rows and set pointers to them */
m[nrl]=(int *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(int)));
if (!m[nrl]) fprintf(stderr, "allocation failure 2 in matrix()");
m[nrl] += NR_END;
m[nrl] -= ncl;
for(i=nrl+1;i<=nrh;i++) m=m[i-1]+ncol;
/* return pointer to array of pointers to rows */
return m;
}