Re: Allocating Four Dimensional Dynamic Arrays...

From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 05/22/04


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



Relevant Pages

  • Re: Gaussian cluster antenna array data
    ... A gaussian array is aimed towards resonant elements in cluster form. ... but these dimensions have not been ...
    (rec.radio.amateur.antenna)
  • RE: Mass Adding Comments
    ... insert code to fill your own array as desired at the beginning of the ... 'Determine number of dimensions in array using Chip Pearson's method ... ' Loop, increasing the dimension index Ndx, until an error occurs. ... 'Exit sub if dimensions do not match ...
    (microsoft.public.excel.programming)
  • Re: Gaussian cluster antenna array data
    ... A gaussian array is aimed towards resonant elements in cluster form. ... but these dimensions have not been ...
    (rec.radio.amateur.antenna)
  • RE: Mass Adding Comments
    ... insert code to fill your own array as desired at the beginning of the ... 'Determine number of dimensions in array using Chip Pearson's method ... ' Loop, increasing the dimension index Ndx, until an error occurs. ... 'Exit sub if dimensions do not match ...
    (microsoft.public.excel.programming)
  • Re: Handling ubound on an uninitialised array
    ... Function ArrDim(vArr As Variant) As Integer ... Dim i As Long, x As Long ... > I believe that Tushar's comment re an UPPERBOUND of -1 may relate> to some functions like split/filter or a scripting dictionary's items> array which return an array if no results were found. ... > I've just written following function which gives the DIMENSIONS of an> array. ...
    (microsoft.public.excel.programming)