TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
Corey Minyard <[log in to unmask]>
Tue, 11 Aug 1998 20:17:18 -0500
Mike Kamrad's message of Tue, 11 Aug 1998 18:48:40 -0400
Mike Kamrad <[log in to unmask]>
Corey Minyard <[log in to unmask]>
text/plain (52 lines)
Mike Kamrad <[log in to unmask]> writes:

> My fellow Ada-Teamers, I am about to venture deeply into the world
> of streams.  In particular, I want to extend the Root_stream_type.
> I haven't found much literature to help guide me.  Can anyone with
> experience in this area respond with their expertise or point me to
> documentation/examples that I might use.  Thanks...mike

It's very easy to extend Root_Stream_Type, just something like:

   type My_Stream_Type is new Ada.Streams.Root_Stream_Type with private;

   procedure Read
     (Stream : in out My_Stream_Type;
      Item   : out Stream_Element_Array;
      Last   : out Stream_Element_Offset);

   procedure Write
     (Stream : in out My_Stream_Type;
      Item   : in Stream_Element_Array);

In the Read and Write procedures, you can do what you want with the
Item parameter, it is an array of elements.  The Last parameter of
Read must be set to the last item put into the Item array.  Then you
can call T'Read, T'Write, T'Input, and T'Output with your stream.  Ada
as a Second Language (second edition) has an Ok section on this.

I did quite a bit of playing with streams for message marshaling, but
in the end I decided not to use it for two reasons:

* I needed inter-compiler and inter-machine transparency, but streams
  offer no guarantees so that I can write portable streams.  There is
  no guarantee of alignment so I can byte-swap and no way I can do
  any data conversion on types without writing my on read and write

* Due to the polymorphic nature of streams, it was extremely slow.  In
  the testing I did, I did a memcpy(), hand-coded marshaling
  procedures that used inlined functions for each element, and a
  stream of a large data structure.  The hand-coded marshaling was 2
  times slower than the memcpy(), the stream around 20 times slower.
  This was on Linux on a Pentium using GNAT, your result may vary.

Since I needed portability of the streamed data and the application
was very message intensive, I instead decided to use ASIS to generate
the inlined marshaling procedures (actually, it was decided that Ada
would not be used, so it really didn't matter after that).

Corey Minyard               Internet:  [log in to unmask]
  Work: [log in to unmask]       UUCP:  [log in to unmask]