[phobos] UnbufferedFile, or, abstracting the File ranges

Denis 2korden at gmail.com
Mon May 10 05:38:44 PDT 2010


On Mon, May 10, 2010 at 4:24 PM, Steve Schveighoffer
<schveiguy at yahoo.com> wrote:
> I would define only 2 i/o functions:
>
> size_t read(void[] b);
> size_t write(const(void)[] b);
>
> And then the various paraphernalia around it (close, open, etc).
>
> The reason to use void[] is because any array data type can be passed to it
> without casting (imagine you wanted to read an array of ints).
>
> Reading and writing a single byte should be discouraged with unbuffered
> streams.  This is how it is in most I/O libs.  You build your unbuffered I/O
> to abstract the OS functions, then build your buffered I/O and fancy
> functionality on top of it.
>
> -Steve
>

I think it should be byte[], not void[]. First, byte[] aren't scanned
for pointers by GC. Second, it hijacks type safety. I believe you need
an explicit cast, even if you are sure about the type of data in the
file (throw in an Endianness if you are still not convienced).


More information about the phobos mailing list