[phobos] UnbufferedFile, or, abstracting the File ranges

Steve Schveighoffer schveiguy at yahoo.com
Tue May 11 11:27:11 PDT 2010





----- Original Message ----
> From: Andrei Alexandrescu <andrei at erdani.com>
> Denis wrote:
> > 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[].

It has been debated forever.

The compiler allows implicit casting to void[], it does not allow implicit casting to byte[] or ubyte[].  So whenever a function's job is just to fill in data from an untyped source (such as a stream) or write data to an untyped sink, void[] is the preferred option.

Whenever you want to *own* an untyped buffer, for example a buffer for buffered I/O, ubyte[] is preferred because of the GC noscan flag associated with it.  However, you can present that buffer as a void[] as necessary.

I guess what I'm saying is, void[] is for interfacing, ubyte[] is for storage.

-Steve



      


More information about the phobos mailing list