std.stream replacement

Stewart Gordon smjg_1998 at yahoo.com
Wed Mar 6 16:08:40 PST 2013


On 06/03/2013 16:36, Steven Schveighoffer wrote:
> On Tue, 05 Mar 2013 18:24:22 -0500, BLM768 <blm768 at gmail.com> wrote:
<snip>
>> Create a range operation like "r.takeArray(n)". You can optimize it to
>> take a slice of the buffer when possible.
>
> This is not a good idea.  We want streams to be high performance.
> Accepting any range, such as a dchar range that outputs one dchar at a
> time, is not going to be high performance.
<snip>

That certain specific types of range can't implement a given operation 
efficiently isn't a reason to reject the idea.

If somebody tries using takeArray on a range that by its very nature can 
only pick off elements one by one, they should expect it to be as slow 
as a for loop.  OTOH, when used on a file, array or similar structure, 
it will perform much better than this.

But thinking about it now, maybe what we need is the concept of a "block 
input" range, which is an input range with the addition of the takeArray 
method.  Of course, standard D arrays would be block input ranges.  Then 
(for example) a library that reads a binary file format can be built to 
accept a block input range of bytes.

Stewart.


More information about the Digitalmars-d mailing list