Impressed with Appender - Is there design/implementation description?

Jon Degenhardt via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 6 13:24:50 PST 2016


On Tuesday, 6 December 2016 at 15:29:59 UTC, Jonathan M Davis 
wrote:
> On Tuesday, December 06, 2016 13:19:22 Anonymouse via 
> Digitalmars-d-learn wrote:
>> On Tuesday, 6 December 2016 at 10:52:44 UTC, thedeemon wrote:
>>
>> [...]
>>
>> > 2. Up until 4 KB it reallocates when growing, but after 4 KB 
>> > the array lives in a larger pool of memory where it can 
>> > often grow a lot without reallocating, so in many scenarios 
>> > where other allocations do not interfere, the data array of 
>> > appender grows in place without copying any data, thanks to 
>> > GC.extend() method.
>>
>> I always assumed it kept its own manually allocated array on a 
>> malloc heap :O
>
> No. The main thing that Appender does is reduce the number of 
> checks required for whether there's room for the array to 
> append in place, because that check is a good chunk of why ~= 
> is expensive for arrays.
> [...]

Thanks everyone for the explanations. I should probably look into 
my data and see how often I'm reaching the 4kb size triggering 
GC.extend() use.

--Jon



More information about the Digitalmars-d-learn mailing list