phobos: What type to use instead of File when doing I/O on streams?

Alex Parrill via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Nov 9 14:02:06 PST 2015


On Monday, 9 November 2015 at 19:42:53 UTC, J.Frank wrote:
> On Monday, 9 November 2015 at 18:44:00 UTC, Alex Parrill wrote:
>> Ranges are streams. file.byLine(Copy) and byChunk are 
>> effectively streams that are ranges.
>
> I might be wrong, but from what I read so far I don't think 
> that "ranges are streams":
>
> - Can you read an arbitrary length of bytes from a range? 
> (Reading by line in my code was just an example.) The only way 
> I see is to make it a byte range. But then reading n bytes 
> would result in n calls to popFront(), which is out of the 
> question for performance reasons. Is this correct?

`myrange.take(array_size).array`

front/popFront are very good candidates for optimization; the 
compiler should be able to inline them, removing all of the 
overhead (GCD and LDC will likely be better at this than DMD, 
though).

> - Can you flush() a range?
>
> - Can you use select() on a range?
>

No, but you can't do either to anything other than file 
descriptors anyway (at least on Linux, dunno about Windows), so 
you may as well pass in a File.


More information about the Digitalmars-d-learn mailing list