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,a30e2d840674d0ef X-Google-Attributes: gid103376,public From: gaukrogi@aston.ac.uk (Rofi) Subject: Re: Stream IO - Correct usage of Set_Index Date: 1999/03/04 Message-ID: <7bmka1$mso$1@whatsit.aston.ac.uk>#1/1 X-Deja-AN: 451248783 References: <7bemc8$snn$1@whatsit.aston.ac.uk> <7bh1me$v4t$1@nnrp1.dejanews.com> Content-Type: text/plain; charset=us-ascii Organization: Aston University Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-03-04T00:00:00+00:00 List-Id: 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 > 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