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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1ea59bb198e88f9f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!feed.cgocable.net!read2.cgocable.net.POSTED!53ab2750!not-for-mail From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: GNAT Ada.Streams Bug? References: <1119161.vGaeJs5laP@linux1.krischik.com> In-Reply-To: <1119161.vGaeJs5laP@linux1.krischik.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Sat, 27 Nov 2004 20:10:45 -0500 NNTP-Posting-Host: 24.150.168.167 X-Complaints-To: abuse@cogeco.ca X-Trace: read2.cgocable.net 1101604248 24.150.168.167 (Sat, 27 Nov 2004 20:10:48 EST) NNTP-Posting-Date: Sat, 27 Nov 2004 20:10:48 EST Organization: Cogeco Cable Xref: g2news1.google.com comp.lang.ada:6572 Date: 2004-11-27T20:10:45-05:00 List-Id: Martin Krischik wrote: > Warren W. Gay VE3WWG wrote: >>Georg Bauhaus wrote: >>>Warren W. Gay VE3WWG wrote: >>>: The point about efficiency is also a good one to raise. For >>>: example, if you String'Read(Stream,Var), GNAT calls the >>>: 'Read routine for each and every Character of the string. >>>: One pines for something more efficient than this, and I >>>: hope for the day when this improves in GNAT. (hint) >>> >>>While not a stream of elements, perhaps Fast_Read in >>>the XML/Ada sources is of interest? >> >>All kinds of possibilities are available when _you_ control >>the format. But when dealing with things like partition >>tables, and existing file formats, I find it disappointing >>that Ada95 struggles with this. I am happy to see that this >>problem is recognized, and will in some way be addressed in >>the Ada200Y standard. > > True. When you do low level programming than you migh want to consider some > of Ada's low level features - and not a very high level IO package. > > In your case: Read the data into an array of Short_Short_Integer and then > use either Unchecked_Convertion or for X'Address use Y'Address to convert > it to your structure. I already mentioned those. The for X'Address approach, you have to be very sure you have the sizes right (for example, it is easy to get sizes wrong based on words vs bytes etc.) This approach BTW, is probably scarey stuff for safety critical code (I'll bet it gets a lot of scrutiny!) Unchecked_Conversion works ok for small things, but is a big CPU waste if you have to do it a lot, or for large items. Not anywhere near the ideal approach IMO. > You should consider one of the lower level IO package to read the data. Ada > has 4 IO packages and the most difficult part about them is to choose the > right one. Well, I don't know what other packages would be "right" for reading in a partition table from an IDE controller. In this example, I extended Ada.Streams.Root_Stream_Type'Class, using code that calls Asm() code to do input/output instructions. This felt like the most elegant way to write the code, and it sure is more elegant than the other approaches I have tried in Ada. Streams works great (except possibly for overhead), with the exception of 3 byte values. So I fixed it by splitting the chs_t type into a separate byte sized head_t and a separate seccyl_t type (16 bits). Then everything worked as expected. Like I said, you _can_ do things like: Status : ide_status_t; begin loop Status := ide_status_t(Input_1(Handle,Status_Port)); ... end loop; Output_1(Handle,Cmd_Port,ide_cmd_t(IDE_IDENTIFY)); _BUT_ the ide_status_t() conversions and friends all over the place are very tedious (try it sometime). Ignoring the C convention type names, it starts to be like C programming with casts all over the place ;-) Don't forget that in a module that does the disk I/O you are dealing with 50+ data types, if you subscribe to the strong type model. That leaves genrics out, unless you want to pay the price of all of those instantiations. In applications like this, it seems to me that the Ada streams is meant to be the correct approach (strong type and convenience). However, for some low level work, I recognize that the for X'Address is the only sensible thing to do. But it must be done with great care, or you could be finding yourself looking at memory corruption bugs. -- Warren W. Gay VE3WWG http://home.cogeco.ca/~ve3wwg