From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c22608a39b6f5e7b X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Dynamic Array Sizing Date: 1999/06/19 Message-ID: #1/1 X-Deja-AN: 491345719 References: <376B1811.666F042@hotmail.com> NNTP-Posting-Date: Fri, 18 Jun 1999 23:39:28 PDT Newsgroups: comp.lang.ada Date: 1999-06-19T00:00:00+00:00 List-Id: On 19 Jun 1999 13:39, Nick Wilson 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).