[phobos] UnbufferedFile, or, abstracting the File ranges

Andrei Alexandrescu andrei at erdani.com
Tue May 11 11:17:55 PDT 2010


Denis wrote:
> 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).

This is an interesting point. It essentially raises a question of what 
situations are best use cases for void[].


Andrei


More information about the phobos mailing list