[phobos] returning void[] from std.file.read()

Robert Jacques sandford at jhu.edu
Sat Sep 25 19:46:37 PDT 2010


On Sat, 25 Sep 2010 17:17:58 -0400, Andrei Alexandrescu  
<andrei at erdani.com> wrote:

> This has come up in http://d.puremagic.com/issues/show_bug.cgi?id=1482.  
> Should std.file.read() return void[] or ubyte[]? There's one matter with  
> assuming that void[] may contain pointers (which is not the case for  
> something read from a file), so possibly ubyte[] is a more accurate type  
> for describng raw bytes.
>
> What are the pros and cons of returning void[] vs. ubyte[]?
>
>
> Andrei

Pro:
Well, the very first thing I always do with std.file.read is to cast the  
data to the type I'm working with. So:

auto data = cast(float[])read("my_data.raw");

vs.

auto data = cast(float[])(cast(void[])read("my_data.raw"));

Having read return ubyte would mean adding an extra cast in several use  
cases

Con:
A void[] array is treated as having pointers in the GC, so extra false  
pointers could be an issue.


More information about the phobos mailing list