[phobos] UnbufferedFile, or, abstracting the File ranges

Steve Schveighoffer schveiguy at yahoo.com
Mon May 10 05:51:38 PDT 2010


The type says nothing about whether it's scanned for pointers or not.  Remember that it's the caller supplying the array, the void[] type just says "pass any type of array in".  The function should not reallocate the array (and even if it did, the scanning bits are copied from the original, not determined by the type).

In other words, the GC cares nothing about type, it only cares what bits are set in the memory block.  And those bits are set on allocation, not when a cast is made or a parameter is passed.

And on hijacking type safety, there is no type safety when reading and writing a stream.  Stream data comes in or goes out as untyped data, so I think using void[] is actually more accurate to what is happening.

-Steve




________________________________
From: Denis <2korden at gmail.com>
To: Discuss the phobos library for D <phobos at puremagic.com>
Sent: Mon, May 10, 2010 8:38:44 AM
Subject: Re: [phobos] UnbufferedFile, or, abstracting the File ranges

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).
_______________________________________________
phobos mailing list
phobos at puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100510/c8389dfc/attachment.html>


More information about the phobos mailing list