comp.lang.ada
 help / color / mirror / Atom feed
From: gaukrogi@aston.ac.uk (Rofi)
Subject: Re: Stream IO - Correct usage of Set_Index
Date: 1999/03/04
Date: 1999-03-04T00:00:00+00:00	[thread overview]
Message-ID: <7bmka1$mso$1@whatsit.aston.ac.uk> (raw)
In-Reply-To: 7bh1me$v4t$1@nnrp1.dejanews.com

In article <7bh1me$v4t$1@nnrp1.dejanews.com>,
	dennison@telepath.com writes:
> In article <7bemc8$snn$1@whatsit.aston.ac.uk>,
>   gaukrogi@aston.ac.uk (Rofi) wrote:
> 
>> 	My problem is using Set_Index to move to a particular data structure
>> that is situated part way through the file.  How do I find out the size of
>> a data structures so that I can use Set_Index correctly.
> 
>> 	I have tried using the attribute Size which appears to return the
>> size of the datastructure in bits.  On this compiler I can divide this by 8
>> and I get the correct values but this method seem to me to be very Adalike.
>> Am I missing something monumentally obvious or ...... ?
> 
> First off, the safe way to find the byte size of an object from 'size is to
> add 7 and then divide by 8. Otherwise you are likely to get a byte size of 0
> for Boolean.

Fair point (should have thought of that one).

> 
> Now for the larger question, I don't think there's a way to know beforehand
> how many storage elements an object will take up in a stream, unless you
> wrote the 'Write routines for the type and the Write routine for the stream
> yourself. For all you know, it may be variable. This is quite likely if
> 'Output is used on a String. But either 'Write or Write could have used some
> kind of compression algorithm as well. You just don't know.

(Sinking feeling in stomarch)

Hadn't thought of that.  Of course that makes what I'm trying to do very
....erm interesting.  I hadn't planned on writing my own Write routines and
the strings should be fixed/bounded ones so .....

> 
> So you may now ask, what are Ada.Streams.Index and Ada.Streams.Set_Index good

<grin>

> for, if you can't use them to skip unnessecary entries in a stream? Well,
> what I'm currently using them for is to keep track of previous locations in a
> stream that I may want to go back to.

Like that idea.  Errrmm (thinking), I'm wondering whether it would be 
possible to actually store positions within a file in the file for use next
time I access the file.  As I know what positions I'm likely to want to go 
to then this could be a nice solution.  Will have to try that one out. 

> 
> To search for a certian entry (eg: an entry with a timestamp past a certian
> time), I will read in all entries one by one, noting their index before I do
> so. When an entry with the proper value is found, I call
> Ada.Streams.Set_Index with the index I saved before I read the item, and
> continue from there.
> 
> So what if you *do* need to know how big every entry in a stream is? Simple;
> create your own stream that keeps track of that information. (more info on
> doing that is available upon request).

Request: more info on doing that :-) (please)
I don't know whether it will the be the best solution for my current problem
but if you have more info easily to hand it would be greatly appreciated.

> 
> T.E.D.

Cheers

Rofi








  reply	other threads:[~1999-03-04  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-01  0:00 Stream IO - Correct usage of Set_Index Rofi
1999-03-02  0:00 ` dennison
1999-03-04  0:00   ` Rofi [this message]
1999-03-04  0:00     ` dennison
1999-03-02  0:00 ` bourguet
1999-03-04  0:00   ` Rofi
replies disabled

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