relative benefit of .reserve and .length
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Apr 28 07:12:07 PDT 2016
On 4/28/16 9:09 AM, Basile B. wrote:
> Out of an appender I believe .reserve can be used to force page creation
> if you know that several pages will be allocated.
> For example for an ubyte[] when .length goes from 16 to 17 the memory
> block *really* allocated by realloc goes from 16 to 4096.
Hm... I don't think that's the behavior that the GC did, but maybe it's
changed.
It should go in powers of 2 up to 4096. And there is extra data needed
for determining the length.
So really, it's from 15 to 16 (may be less now that the GC calls dtors),
and it should go from 16 bytes to 32 with normal append.
If you reserve, you can specify a higher starting point (e.g. 4096 if
you wish).
-Steve
More information about the Digitalmars-d-learn
mailing list