comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison<dennison@telepath.com>
Subject: Re: Ada.Streams.Read Length Paramenter is not IN?
Date: Tue, 07 Aug 2001 18:39:29 GMT
Date: 2001-08-07T18:39:29+00:00	[thread overview]
Message-ID: <BBWb7.1834$NJ6.7602@www.newsranger.com> (raw)
In-Reply-To: slrn9mvbej.hs.lutz@taranis.iks-jena.de

In article <slrn9mvbej.hs.lutz@taranis.iks-jena.de>, Lutz Donnerhacke says...
>procedure Read(
>  Stream : in out XXX_Stream_Type;
>  Item   :    out Stream_Element_Array;
>  Last   :    out Stream_Element_Offset);
..
>OTOH each T'Read or T'Input procedure exactly knows how many
>Storage_Elements are needed to fullfill the request. Why is this information
>not given to the Stream.Read procedure?

It is. That information is Item'length. One of the nifty things about Ada is
that we don't need a separate parameter to specify how large a passed-in buffer
is.

You may protest that there's no guarantee that they won't give you a bigger
buffer than they need, but the guarantee is implied. Think about it. If you gave
back more data than they needed, what could they do with the extra? How would
they get it back in the stream so it could go to the rightful owner? There's no
way. So they will call you with the exact sized buffer for the data they want to
read.

>BTW: Do I understand the procedure semantics correctly, if I return Item and
>     Last := Item'Last generally. But in the case of EOF returning Item
>     larger than normally and set Item'Last to the last valid element.
>     Would it be not simpler to have the following procedure?

The data returned couldn't be *larger*, (the buffer is only Item'Last long). It
could be smaller due to EOF, in which case I'd expect either you to return Last
< Item'Last, or you to raise an exception. I think Streams.Stream_IO raises
END_ERROR.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



  reply	other threads:[~2001-08-07 18:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-07  9:02 Ada.Streams.Read Length Paramenter is not IN? Lutz Donnerhacke
2001-08-07 18:39 ` Ted Dennison [this message]
2001-08-07 20:18   ` Lutz Donnerhacke
2001-08-07 19:48 ` tmoran
2001-08-07 20:21   ` Lutz Donnerhacke
replies disabled

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