[Gc] GC Warning: Repeated allocation of very large block

Bruce Hoult bruce at hoult.org
Sun Oct 29 17:24:18 PST 2006


On 10/30/06, mijobee at mijobee.com <mijobee at mijobee.com> wrote:
> ... realloc size increment should be fairly large (e.g. a factor of
> 3/2) for this to exhibit reasonable performance
>
> Is this just saying that the amount of memory allocated should be
> doubled or tripled when growing a memory region when implementing
> something like a variable length array class?  Thanks in advance.

Doubled or tripled is probably too much, unless you are *much* more
sensitive to speed than to memory usage.  Increasing by a factor of
approximately 1.414 each time (sqrt(2)) tends to be a good compromise
... and the nicest way to do that is probably to use a sequence like
2,3,4,6,8,12,16,24,32,48,64,96,128,192,256 ... that is to multiply by
1.5 (3/2) one time and then 1.3333 (4/3) the next time.  If you do
that, then each time just after you expand the array each item has
been copied to a new array on average 3.4 times.


More information about the Gc mailing list