dmd 1.057 and 2.041 release

biozic biozic at free.fr
Tue Mar 9 07:10:10 PST 2010


Steven Schveighoffer Wrote:

>   * shrinkToFit(T[] arr): This one is a bit tricky and technically unsafe.   
> It reduces the size of the "allocated" length to fit the length of the  
> array.  The allocated length is the length that the runtime assumes is  
> being used of the memory block.  This is what aids in preventing stomping,  
> so use with care.  You can achieve stomping if you use shrinkToFit on a  
> slice, but still have references to the trimmed data.  Example:
> 
> string s = "12345".idup;
> string slice = s[0..2];
> slice.shrinkToFit(); // tells the runtime that you will no longer use any data beyond the slice
> slice ~= "00"; // appends in place, overwriting immutable data referenced  

Actually, slice.capacity *increases* from 0 to s.capacity when calling shrinkToFit, doesn't it? So "stomp" or "prepare_for_stomping" could be a better name.





More information about the Digitalmars-d-announce mailing list