The purpose of D (GC rant, long)

Sean Kelly sean at f4.ca
Fri Oct 27 06:40:33 PDT 2006


Dave wrote:
> Sean Kelly wrote:
>> Now that memory is not freed when string.length is set to zero it's 
>> quite possible to avoid most reallocations simply by preallocating in 
>> buffers before using them (ie. set length to some large number and then 
> 
> I did not know that had been changed.. Is that now part of the language 
> 'spec' somewhere as well?

No.  It was implemented in 170-172 by request from Derek.  I don't know 
the issue number offhand.

> I'm betting this has been discussed or at least proposed, but here goes 
> again; let's get an array.reserve at least for native arrays (that could 
> be implemented as {arr.length = nnn; arr.length = 0;}). That way it 
> would make for less of a hack than re/setting the length, and also 
> codify it as part of the language.

I agree that this would be useful.  Though it would probably be more like:

size_t tmp = arr.length; arr.length = nnn; arr.length = tmp;


Sean



More information about the Digitalmars-d mailing list