Why does array loses it internal capacity on length change?

JR via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 12 02:07:36 PST 2016


On Saturday, 12 March 2016 at 09:56:48 UTC, Uldis wrote:
>         dump(a); // line 10
>         a.length = 0;
>         dump(a);
>         a ~= [1,2,3];
>         dump(a);
>         a.length = 0;
>         dump(a);
>         a ~= [4,5,6];
>         dump(a);

I'll let others more knowledgeable explain why, but tack an 
a.assumeSafeAppend() after the length change and you'll get your 
desired behaviour.


More information about the Digitalmars-d-learn mailing list