Re: Allocating Four Dimensional Dynamic Arrays...
From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 05/22/04
- Next message: Gianni Mariani: "Re: Pulling the type declaration out of a variable?"
- Previous message: Steven T. Hatton: "Pulling the type declaration out of a variable?"
- In reply to: John Harrison: "Re: Allocating Four Dimensional Dynamic Arrays..."
- Next in thread: fivelitermustang: "Re: Allocating Four Dimensional Dynamic Arrays..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 22 May 2004 23:48:03 +1000
"John Harrison" <john_andronicus@hotmail.com> wrote in message
news:2h8dhdFaaq47U1@uni-berlin.de...
|
| "fivelitermustang" <fivelitermustang@shaw.ca> wrote in message
| news:5098508bd22f7744b7ce72397e5dfad1@localhost.talkaboutprogramming.com...
| > I haven't covered classes yet so I'm not quite familiar with the workings
| > of the code snippet you have posted.
| >
| > I have the code written to iterate through a static four-dimensional
| > array. The array is initialized in the pyramid structure and the remaining
| > values are zero. It works properly and moves through them and I get the
| > proper results. I just need to get this dynamically allocated.
| >
| > Since I'm not really that familiar with classes isn't it possible to
| > initialize this array with loops and making pointers?
| >
| > If that is possible could you just show me the proper syntax to make a 4D
| > square/rectangular array using the method that I was using to make that 2D
| > dynamic array?
| >
|
| I'm confused about what you want, but here some code that allocates a 4D
| array. It's the same as your 2D code but expanded to 4 dimensions. I'm not
| sure what dimensions you actually want (some combination of C and n in your
| original post I think) so I've used D1, D2, D3 and D4 for the dimensions,
| you can substitute the values you want.
|
| double**** v;
| v = new double***[D1];
| for (int i = 0; i < D1; ++i)
| {
| v[i] = new double**[D2];
| for (int j = 0; j < D2; ++j)
| {
| v[i][j] = new double*[D3];
| for (int k = 0; k < D3; ++k)
| {
| v[i][j][k] = new double[D4];
| }
| }
| }
|
| But this doesn't work if you want a variable number of dimensions, which is
| what I thought you wanted. Nor does it allocate memory in a single block,
| which is another thing I thought you wanted. So I'm a bit confused.
|
| There's nothing special about classes, anything you can do inside a class
| you can also do outside a class. What classes do however is wrap up all your
| code in an easy to use package, something that might be quite useful here.
The OP may be much better off with nested vectors, wrapped
up in an class that provides suitable accessors. This would
allow for a variable number of dimensions, not to mention
ease the pain and danger of memory management on your own.
Cheers.
Chris Val
- Next message: Gianni Mariani: "Re: Pulling the type declaration out of a variable?"
- Previous message: Steven T. Hatton: "Pulling the type declaration out of a variable?"
- In reply to: John Harrison: "Re: Allocating Four Dimensional Dynamic Arrays..."
- Next in thread: fivelitermustang: "Re: Allocating Four Dimensional Dynamic Arrays..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|