RFC on range design for D2

Sean Kelly sean at invisibleduck.org
Thu Sep 11 10:48:01 PDT 2008


bearophile wrote:
> Oskar Linde (and Andrei Alexandrescu):
>> So by removing ~= from T[], T[] becomes a pure slice type.
> 
> Appending to the built-in dynamic arrays is a fundamental operation (I use it hundred of times in my code) so if the purpose is just to avoid problems when extending slices, a different solution can be invented.
> For example adding the third (capacity) field to the dyn array struct, the last bit of the capacity field can be used to tell apart slices from true whole arrays. So at runtime the code knows how to extend/append the array/slice correctly. This slows down the appending itself a little, but it's better than having to use an ugly ArrayBuilder everywhere.

I'd think that adding a capacity field should actually speed up append 
operations, since the GC wouldn't have to be queried to determine this 
info.  And as in another thread, the capacity of all slices should 
either be zero or the size of the slice, thus forcing a realloc for any 
append op.


Sean


More information about the Digitalmars-d-announce mailing list