comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: Dynamic Array Sizing
Date: 1999/06/19
Date: 1999-06-19T00:00:00+00:00	[thread overview]
Message-ID: <m3vhckd737.fsf@mheaney.ni.net> (raw)
In-Reply-To: 376B1811.666F042@hotmail.com

On 19 Jun 1999 13:39, Nick Wilson <snow_moose@hotmail.com> wrote:

> I have a file containing an variable amount of data that I want to read
> into an array. My problem is that if I use a dynamic array, eg
> 
> type Array_Store is array (integer range <>) of boolean;

Any reason you're using an index subtype of Integer?  The usual Ada
idiom is to use Positive:

  type Array_Store is array (Positive range <>) of Boolean;


> I have to declare an actual array sometime before reading the values
> into the array, but don't know what size to make the array.

Is the number of values stored in the file, perhaps at a specific
offset?  Then you can read in the length, declare the array object, and
then read into the array:

  declare
    N : Positive;  -- or Natural?
  begin
    Read (File, N);  -- maybe use Direct_IO or Stream_IO
 
    declare
      Values : Array_Store (1 .. N);
    begin
      Read (File, Values);
    end;
  end;


> I can do two passes of the file, one to see the size, then declare the
> array in a block and do another pass to read the values into it.

Do you need to read in all the data at once (into an array)?  Can't you
just read the data from the file directly?

There's not much difference between reading from a randomly-accessed
array object, versus reading from a randomly-accessed file object.

If you don't need random access, then you could just use Sequential_IO.

 
> My problem comes about when I want to use functions which are
> externally available outside this package to lookup the array
> values. In order to do so, I will need to have the funcitons inside
> the declare block so they can access the array, but this doesn't seem
> possible ?  Is there a nicer way to do the above in ADA to get access
> to my array from outside the package ?

I don't know what you're trying to say here.  Post a snippet of code,
enough for us to see the module structure.


I don't think you need to read the data into an array.  Just read from
the file directly, using Direct_IO (for random-access) or Sequential_IO
(for sequential access).







  parent reply	other threads:[~1999-06-19  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-19  0:00 Dynamic Array Sizing Nick Wilson
1999-06-19  0:00 ` Tom Moran
1999-06-19  0:00 ` jerry
1999-06-19  0:00   ` Matthew Heaney
1999-06-19  0:00     ` jerry
1999-06-20  0:00       ` Matthew Heaney
1999-06-21  0:00         ` jerry
1999-06-19  0:00   ` jerry
1999-06-19  0:00 ` Matthew Heaney [this message]
1999-06-20  0:00   ` Nick Wilson
1999-06-20  0:00     ` Matthew Heaney
replies disabled

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