[phobos] UnbufferedFile, or, abstracting the File ranges

Steve Schveighoffer schveiguy at yahoo.com
Tue May 11 10:47:55 PDT 2010


Yes, you are right.  byChunk is OK.  byByte is still not, calling a syscall for each byte is not very fast, no matter what the source of the input.

I would surmise that better than byByte is byVariableChunk (for lack of a better term) -- read as much as possible up to n bytes.  This should be good for tty inputs and the most efficient for not-always-available input.  byChunk I would imagine should block until it gets exactly the chunk size or EOF, whereas byVariableChunk would block only until it gets at least one byte.

You can always do byChunk with a chunk size of 1 if you insist on byte-by-byte reading :)  I just don't think it's worth the special case.

byChar is along the same lines as byLine, it requires parsing each byte.

-Steve



----- Original Message ----
> From: Andrei Alexandrescu <andrei at erdani.com>
> To: Discuss the phobos library for D <phobos at puremagic.com>
> Sent: Tue, May 11, 2010 11:14:55 AM
> Subject: Re: [phobos] UnbufferedFile, or, abstracting the File ranges
> 
> Steve Schveighoffer wrote:
> Re: byLine and byChunk, I don't think these 
> are a good idea on unbuffered files.

byLine is onerous because it reads 
> one character at a time, but byChunk makes a lot of sense. It essentially is 
> buffering straight in user's buffers. A lot of Unix utilities do 
> that.

> For example, your current implementation will be extremely 
> slow.  Reading one char at a time is OK on a buffered file, because most 
> times its just a simple fetch of a char from a buffer.  But your 
> implementation reads a single character at a time from the actual file on disk, 
> a very slow operation.
> 
> I think unbuffered files are good for 
> when you want to handle the buffering yourself, or when you want to pass them to 
> child processes.

Actually a great use case is character-level unbuffered 
> files when you want to do something for each keypress off a 
> tty.


Andrei
_______________________________________________
phobos 
> mailing list

> href="mailto:phobos at puremagic.com">phobos at puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos


      


More information about the phobos mailing list