Re: [Flightgear-devel] Arrays of doubles

2004-04-14 Thread Gerhard Wesp
On Fri, Apr 09, 2004 at 08:03:49AM -0500, Jon Berndt wrote:
 class.  All I want right now is how do I allocate storage for a 2
 dimensional array of doubles, so that I can use the standard accessor
 operators:
 
 myDouble = Data[n][m];

If you insist on the [][] syntax, I'd strongly recommend a 

  std::vector std::vector double   .

If not, you can use one of the many C++ matrix implementations floating
around, for example (shameless plug :-) cpp-lib, which is available from
my homepage:

   http://www.cosy.sbg.ac.at/~gwesp/

Here you can access the elements by 

  Data( n , m )

( 1 = n = rows , 1 = m = columns ) (Similar to FORTRAN notation).

Kind regards,
-Gerhard
-- 
Gerhard Wesp o o   Tel.: +41 (0) 43 5347636
Bachtobelstrasse 56   |   http://www.cosy.sbg.ac.at/~gwesp/
CH-8045 Zuerich  \_/   See homepage for email address!

___
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel


[Flightgear-devel] Arrays of doubles

2004-04-09 Thread Jon Berndt
Is there a better way to allocate storage for an array than this:


double** Allocate(void)
{
  Data = new double*[nRows+1];
  for (int r=0; r=nRows; r++) {
Data[r] = new double[nCols+1];
for (int c=0; c=nCols; c++) {
  Data[r][c] = 0.0;
}
  }
  return Data;
}



___
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel


Re: [Flightgear-devel] Arrays of doubles

2004-04-09 Thread Mathias Fröhlich
On Freitag, 9. April 2004 14:26, Jon Berndt wrote:
 Is there a better way to allocate storage for an array than this:


 double** Allocate(void)
 {
   Data = new double*[nRows+1];
   for (int r=0; r=nRows; r++) {
 Data[r] = new double[nCols+1];
 for (int c=0; c=nCols; c++) {
   Data[r][c] = 0.0;
 }
   }
   return Data;
 }

Depends on what you need.
If you really need an array of an array there is nothing I know of.
If you need a 2-dimensional/n-dimensional array for the upcomming 
multidimensional lookup tables, you told about, I would suggest to allocate 
the space in one block and implement access functions just like we did for 
the Matrix class.

   Greetings

Mathias

-- 
Mathias Fröhlich, email: [EMAIL PROTECTED]

___
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel


RE: [Flightgear-devel] Arrays of doubles

2004-04-09 Thread Jon Berndt
 On Freitag, 9. April 2004 14:26, Jon Berndt wrote:
  Is there a better way to allocate storage for an array than this:
 
 
  double** Allocate(void)
  {
Data = new double*[nRows+1];
for (int r=0; r=nRows; r++) {
  Data[r] = new double[nCols+1];
  for (int c=0; c=nCols; c++) {
Data[r][c] = 0.0;
  }
}
return Data;
  }

 Depends on what you need.
 If you really need an array of an array there is nothing I know of.
 If you need a 2-dimensional/n-dimensional array for the upcomming
 multidimensional lookup tables, you told about, I would suggest
 to allocate
 the space in one block and implement access functions just like
 we did for
 the Matrix class.

I am afraid it is much simpler than that: all I need is a 2 dimensional
array, n X m.

Jon


___
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel


Re: [Flightgear-devel] Arrays of doubles

2004-04-09 Thread Mathias Fröhlich
On Freitag, 9. April 2004 14:39, Jon Berndt wrote:
 I am afraid it is much simpler than that: all I need is a 2 dimensional
 array, n X m.

For such a simple array it is best to use

data = new double[n*m]

and have access functions:

double Entry(unsigned int i,unsigned int j) const { return 
data[(i-1)*n+j-1]; }
double Entry(unsigned int i,unsigned int j) { return data[(i-1)*n+j-1]; }

Where the -1 terms are usually optimized away by the compiler.
Alternatively you can start indexing with 0 ...

For constants in the arguments to the Entry(..) function, this will be faster 
than having an array of arrays, since the compiler can compute the offset to 
the array pointer at compile time. If you have an array of arrays the 
compiler needs to lookup array pointer in the first array and can then use 
the precomputed offset.
For nonconst indices this kind of depends on the architecture and the 
compiler ...
You will use more memory if you use this array of arrays ...

Greetings

 Mathias

-- 
Mathias Fröhlich, email: [EMAIL PROTECTED]

___
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel


RE: [Flightgear-devel] Arrays of doubles

2004-04-09 Thread Jon Berndt
 For such a simple array it is best to use

 data = new double[n*m]

 and have access functions:

 double Entry(unsigned int i,unsigned int j) const { return
 data[(i-1)*n+j-1]; }
 double Entry(unsigned int i,unsigned int j) { return data[(i-1)*n+j-1]; }


Yes, this may come at some time.  I am debuggin the additions to the Table
class.  All I want right now is how do I allocate storage for a 2
dimensional array of doubles, so that I can use the standard accessor
operators:

myDouble = Data[n][m];

??

Jon


___
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel


Re: [Flightgear-devel] Arrays of doubles

2004-04-09 Thread Mathias Fröhlich
On Freitag, 9. April 2004 15:03, Jon Berndt wrote:
 I am debuggin the additions to the Table 
 class.

 All I want right now is how do I allocate storage for a 2 
 dimensional array of doubles, so that I can use the standard accessor
 operators:

 myDouble = Data[n][m];

 ??
Hmm, two possibilities.
You are talking about FGTable, I think.

Either you have to use the array of arrays solution. This is required in this 
case if the array *needs* to have a dynamic size.

Alternatively I can see for this application and for debugging, depends on 
what you debug, that you declare 

double Data[one sufficieltly large number][an other sufficiently largenumber];

instead of

double** Data;

Using this you can just use the syntax from above to access the array members.
As told, not for production, only for debuging ...

So what is the problem? What do you need to debug?

  Greetings

   Mathias

-- 
Mathias Fröhlich, email: [EMAIL PROTECTED]

___
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel


RE: [Flightgear-devel] Arrays of doubles

2004-04-09 Thread Jon Berndt
I'll send you the problem offline.

 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] Behalf Of Mathias
 Fröhlich
 Sent: Friday, April 09, 2004 8:16 AM
 To: FlightGear developers discussions
 Subject: Re: [Flightgear-devel] Arrays of doubles


 On Freitag, 9. April 2004 15:03, Jon Berndt wrote:
  I am debuggin the additions to the Table
  class.

  All I want right now is how do I allocate storage for a 2
  dimensional array of doubles, so that I can use the standard accessor
  operators:
 
  myDouble = Data[n][m];
 
  ??
 Hmm, two possibilities.
 You are talking about FGTable, I think.

 Either you have to use the array of arrays solution. This is
 required in this
 case if the array *needs* to have a dynamic size.

 Alternatively I can see for this application and for debugging,
 depends on
 what you debug, that you declare

 double Data[one sufficieltly large number][an other sufficiently
 largenumber];

 instead of

 double** Data;

 Using this you can just use the syntax from above to access the
 array members.
 As told, not for production, only for debuging ...

 So what is the problem? What do you need to debug?

   Greetings

Mathias

 --
 Mathias Fröhlich, email: [EMAIL PROTECTED]

 ___
 Flightgear-devel mailing list
 [EMAIL PROTECTED]
 http://mail.flightgear.org/mailman/listinfo/flightgear-devel


___
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel


Re: [Flightgear-devel] Arrays of doubles

2004-04-09 Thread Mathias Fröhlich
On Freitag, 9. April 2004 15:31, Jon Berndt wrote:
 I'll send you the problem offline.
Ok.

Greetings

Mathias

-- 
Mathias Fröhlich, email: [EMAIL PROTECTED]

___
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel