D array expansion and non-deterministic re-allocation

Bartosz Milewski bartosz-nospam at relisoft.com
Tue Nov 17 16:21:21 PST 2009


dsimcha Wrote:

> 
> The one thing that I think has been missing from this discussion is, what would be
> the alternative if we didn't have this "non-deterministic" reallocation?  How else
> could you **efficiently** implement dynamic arrays?

In the long run (D3), I proposed using the "unique" type modifier. If an array is unique, the compiler knows that there are no slices to worry about, and it can use in-place reallocation to its heart content. That pretty much solves the performance problem. 

In the short run (D2), I would suggest sticking to "reallocate on every extension" semantics (especially in SafeD) and provide a library solution (a la C++ std::vector) where the performance of appending is an issue. 



More information about the Digitalmars-d mailing list