"fivelitermustang" <fivelitermustang@shaw.ca> wrote in message
news:26d903d6bba190d37b89f86b8bbf2560@localhost.ta lkaboutprogramming.com...[color=blue]
> Actually, how would I go about allocating a four-dimensional dynamic
> array?
>
> I only know how to make two dimensional dynamic arrays:
> double **v;
> v = new double*[C];
> for (int i=0; i<C; i++)
> {
> v[i] = new double[n];
> }
>
> Well my plans have changed a bit and I need to make an array to store
> matrices "v" (like the one I allocated above with dynamic dimensions C*n).
> I'm not going to use the code above... I want to allocate all four
> dimensions in one snippet. It needs to be done in a similar manner because
> I'm not sure that the memory will be contiguous.
>
> What I want to do is have an array going a variable number of levels deep,
> and the row after the previous will have "n" times the amount of matrices
> "v".
>
> For example... if n was 3:
>
> On the first row there would contain 1 matrix "v".
> On the second row there would contain 3 matrix "v".
> On the third row there would contain 9 matrix "v".
>[/color]
[color=blue]
> In the program I am writing it would be convenient to access these members
> like this:
>
> example:
> [1, 2, 1, 2]
> This would correlate to the matrix v found on the second row and third
> column of this matrix. It would access the second row and third column of
> the member v that was seleced by the first two parameters)
>[/color]
A big issue is whether the number of dimensions is a constant known at
compile time, or whether you want to vary that at run time. Most of the time
you say four dimensions but then you say 'a variable number of levels deep'.
If the former then look at multi_array from boost,
http://www.boost.org/libs/multi_array/doc/index.html.
If the later then its not easy. One problem is how you access the
multi-dimensional array when you need a variable number integers to specify
an element. You would have to overload operator() with a variable number of
parameters I think.
In any case it sounds a very unwieldy data structure, I doubt that you
really need to do this, but then I don't know what problem you are actually
trying to solve.
john