assumeSafeAppend inconsistent when multiple slices in use

Steven Schveighoffer schveiguy at yahoo.com
Thu Apr 7 13:45:00 PDT 2011


On Thu, 07 Apr 2011 15:22:10 -0400, simendsjo <simen.endsjo at pandavre.com>  
wrote:

> I'm having some problems explaining it as I'm not sure about the correct  
> terminology (I should have drawn some pictures..), but I'll try.
>
> The runtime doesn't track the "original" array and the slices (for this  
> example at least - it obviously do for the sake of gc).
> Internally it keeps an address to the current endpoint in the chunk of  
> memory like array.ptr+array.length.
> Any array that ends on this address is allowed to append fill the memory  
> without reallocating as it points to the end of the array. But whenever  
> a slice that's allowed to append/change length changes, it will change  
> the endpoint address for the chunk of memory, and thus the other slices  
> probably points at an earlier element and cannot append.
> Any element not pointing at the endpoint will return capacity==0.

This all looks correct.

-Steve


More information about the Digitalmars-d-learn mailing list