From: Gautier write-only on
Jeffrey R. Carter:
> If you're
> really paranoid, you can add a test that Unsigned_8'Size = Stream_Element'Size,
> which you seem to be assuming.

Yet a bit more paranoid: checking the size of arrays!

workaround_possible: Boolean;

procedure Check_workaround is
test_a: constant Byte_Buffer(1..10):= (others => 0);
test_b: constant Ada.Streams.Stream_Element_Array(1..10):= (others
=> 0);
begin
workaround_possible:= test_a'Size = test_b'Size;
end Check_workaround;

It's the code I've put into Zip-Ada - big success!
:-)
_________________________________________________________
Gautier's Ada programming -- http://sf.net/users/gdemont/
NB: For a direct answer, e-mail address on the Web site!
From: Randy Brukardt on
"Jeffrey R. Carter" <spam.jrcarter.not(a)spam.acm.org> wrote in message
news:hcfdpo$p62$1(a)news.tornevall.net...
> Gautier write-only wrote:
>> On 30 Okt., 01:39, "Jeffrey R. Carter"
>> <spam.jrcarter....(a)spam.acm.org> wrote:
>>
>>> And if you overlay the Stream_Element_Array onto the Buffer, thus
>>> eliminating
>>> the copying and the stream attribute operations?
>>
>> With an Unchecked_conversion ?
>
> No, that still does a copy.

It doesn't have to, there is a permission to avoid copying in 13.9(12). So
it depends on what the compiler is able to do optimization-wise.

Randy.


From: Randy Brukardt on
"Gautier write-only" <gautier_niouzes(a)hotmail.com> wrote in message
news:715d78f4-9b01-4598-88c1-6fc202983bae(a)p35g2000yqh.googlegroups.com...
> On 30 Okt., 04:36, Georg Bauhaus <rm-host.bauh...(a)maps.futureapps.de>:
>
>> I finally thought that the above procedures are faster than 'Read
>> or 'Write because the latter are defined in terms of stream elements:
>> When there is a composite object like b : Buffer and you
>> 'Write it, then for each component of b the corresponding 'Write
>> is called. This then writes stream elements, probably
>> calling Stream_IO.Write or some such in the end.
>> So Write from above appears closer to writing bulk loads
>> of stream elements than a bulk load of 'Writes can be.
>
> Sure, it is the safe way: write records field by field, arrays element
> by element (that recursively). The compiler avoids problems with non-
> packed data. Nothing against that. The general case is well done,
> fine. But the compiler could have a look a the type left to the
> attribute and in such a case (an array of Unsigned_8, or a String)
> say: "Gee! that type Buffer is coincidentally the same as
> Stream_Element_Array, then I take the shortcut to generate the code to
> write the whole buffer and, this time, not the code to write it
> element by element".

IMHO, Ada compilers should do that. (There's specifically a permission to do
this optimization in Ada 2005: 13.13.2(56/2).) That's an intergral part of
the stream attribute implementation on Janus/Ada. (Disclaimer: the entire
stream attribute implementation on Janus/Ada doesn't work right, quite
probably because it is too complicated. So perhaps there is a reason that
other Ada compilers don't do that. :-) Note, however, that it is pretty rare
that you could actually do that (only about 15% of the composite types I've
seen in Janus/Ada would qualify). So I'm not surprised that implementers
have left that capability out in favor of things that happen more often.

Randy.


From: Gautier write-only on
On 2 nov, 22:37, "Randy Brukardt" <ra...(a)rrsoftware.com> wrote:

> IMHO, Ada compilers should do that. (There's specifically a permission to do
> this optimization in Ada 2005: 13.13.2(56/2).)

Excellent news!

> That's an intergral part of
> the stream attribute implementation on Janus/Ada. (Disclaimer: the entire
> stream attribute implementation on Janus/Ada doesn't work right, quite
> probably because it is too complicated. So perhaps there is a reason that
> other Ada compilers don't do that. :-) Note, however, that it is pretty rare
> that you could actually do that (only about 15% of the composite types I've
> seen in Janus/Ada would qualify).

Sure - but imagine that these 15% might transport 95% of the
information. It could happen, couldn't it ?
And if type T qualifies, a record type R with fields of types T,U,V (U
and V not qualifying) will be also transmitted faster, an array of R
will also go faster, and so on...

> So I'm not surprised that implementers
> have left that capability out in favor of things that happen more often.

I am not surprised either...

Gautier
From: Gautier write-only on
Hello,
Following the discussion about stream attributes for arrays of bytes
(see Performance of the Streams 'Read and 'Write), I have an idea on
how to improve GNAT on that point.
Basically, GNAT has a shortcut for the type {Wide_}String.
The idea would consist in applying the same when the base type is an
array of bytes (any array-of-mod-2**8 type which can be safely detyped
to a String).
More concretely, it would consist in adding at the end of
Find_Stream_Subprogram (exp_attr.adb) something like:

if Is_Array_Type(Typ) and then
Is_Bit_Packed_Array (Typ) and then
Component_Size (Typ) = 8 and then
then
Comp_Typ:= Component_Type (Typ);
if Is_Modular_Integer_Type(Comp_Typ) and then
[modulus ??] (Comp_Typ) = 2**8
then
[ go ahead with some unchecked conversion to String ]
return [the right thing];
end if;
end if;

Now, I have no experience with building GNAT.
Is there an easy way on Windows ?
Or could someone give a try on a "working" GCC tree ?
TIA
_________________________________________________________
Gautier's Ada programming -- http://sf.net/users/gdemont/
NB: For a direct answer, e-mail address on the Web site!