why does array appending add a page size instead of doubling ?

monarch_dodra monarchdodra at gmail.com
Sun Feb 3 00:09:59 PST 2013


On Sunday, 3 February 2013 at 06:02:04 UTC, Ali Çehreli wrote:
>
> Its output is different in that the number of allocations is 
> less than C++ but the total number of elements that get moved 
> are more:
>
> [SNIP]
>
> Ali

Note that dynamic arrays are generic containers, so they aren't 
exactly optimized for anything. You could try that test with the 
"made for appending" std.array.appender: It always tries to 
extend without reallocating, and only relocates when the current 
memory segment is 100% full.

Furthermore, when it *does* relocate, it use D-style memmove 
without calling postblit. Independent of language, and with the 
requirement of contiguous memory, I can't really think of a 
scheme that could be better than that...?


More information about the Digitalmars-d-learn mailing list