comp.lang.ada
 help / color / mirror / Atom feed
From: johnherro@aol.com (John Herro)
Subject: Re: array of matrices
Date: 1996/05/03
Date: 1996-05-03T00:00:00+00:00	[thread overview]
Message-ID: <4mdjbq$df7@newsbf02.news.aol.com> (raw)
In-Reply-To: 4m9aeb$d0e@news2.h1.usa.pipeline.com


boaz@usa.pipeline.com(Boaz Chow) writes:
> type Matrix is array (integer range <>, integer range <>) of integer; 
> I want to set up a variable for array (1..N) of Matrix; 
> I know this won't work:  A : array (1..N) of Matrix;
     You're right.  You can't directly set up an array of an unconstarined
type.  There are two things you can do.  One is to allow for the largest
possible matrix for every element in the array, and keep track of the
number of rows and columns actually used:

type Square15 is array(1 .. 15, 1 .. 15) of Integer;
type Matrix is
   record
      Data    : Square15;
      Rows    : Integer;
      Columns : Integer;
   end record;
...
A : array(1 .. N) of Matrix;
...
A(1).Rows    := 5;
A(1).Columns := 15;
A(2).Rows    := 15;
A(2).Columns := 7;
...

This has the disadvantage of using more memory than you actually need, but
is perhaps a bit simpler than the second way.  The second way is to
declare an array of *pointers*.  Each pointer can point to a different
size matrix:

type Matrix is array(Integer range <>, Integer range <>) of Integer;
type Ptr is access Matrix;
...
A : array(1 .. N) of Ptr;
...
A(1) := new Matrix(1 .. 5, 1 .. 15);
A(2) := new Matrix(1 .. 15, 1 .. 7);
...

I hope this helps.
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor




  reply	other threads:[~1996-05-03  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-02  0:00 array of matrices Boaz Chow
1996-05-03  0:00 ` John Herro [this message]
1996-05-04  0:00   ` Boaz Chow
1996-05-04  0:00     ` John Herro
1996-05-10  0:00   ` Ron J Theriault
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox