[phobos] Array preallocate function

Andrei Alexandrescu andrei at erdani.com
Sat Feb 20 09:18:55 PST 2010

Steve Schveighoffer wrote:
> This is a good idea.  I still think a function to do this should be
> available, so you can do the allocation in one step instead of
> declaring an array and then setting its capacity.
> What about the issue of shrinking the allocated size as in the loop I
> showed?  Should this be allowed via builtin arrays or reserved to a
> wrapper?

I think regardless of what we do, there will be people who will say 
buffer.length = 0 if they want to reuse a buffer. I think we should do 
something sensible in such cases. The case I don't think we want to 
endorse as an idiom is "for efficiency, initialize needlessly a large 
buffer and then assign its length to zero".


More information about the phobos mailing list