comp.lang.ada
 help / color / mirror / Atom feed
From: "Warren W. Gay VE3WWG" <ve3wwg@NoSpam.cogeco.ca>
Subject: Re: GNAT Ada.Streams Bug?
Date: Sat, 27 Nov 2004 20:10:45 -0500
Date: 2004-11-27T20:10:45-05:00	[thread overview]
Message-ID: <sA9qd.13612$hp3.1959122@read2.cgocable.net> (raw)
In-Reply-To: <1119161.vGaeJs5laP@linux1.krischik.com>

Martin Krischik wrote:
> Warren W. Gay VE3WWG wrote:
>>Georg Bauhaus wrote:
>>>Warren W. Gay VE3WWG <ve3wwg@nospam.cogeco.ca> 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



  reply	other threads:[~2004-11-28  1:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-25 17:41 GNAT Ada.Streams Bug? Warren W. Gay VE3WWG
2004-11-25 19:40 ` Jeff C r e e.m
2004-11-26  4:11   ` Warren W. Gay VE3WWG
2004-11-26  9:49     ` Georg Bauhaus
2004-11-26 17:30       ` Warren W. Gay VE3WWG
2004-11-27  7:34         ` Martin Krischik
2004-11-28  1:10           ` Warren W. Gay VE3WWG [this message]
2004-11-29  7:50         ` tmoran
2004-11-29 17:47           ` Warren W. Gay VE3WWG
2004-11-26 22:47     ` Simon Wright
2004-11-27 14:42       ` Warren W. Gay VE3WWG
2004-11-27 17:25         ` Simon Wright
replies disabled

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