Pop quiz [memory usage]
Fawzi Mohamed
fmohamed at mac.com
Sat Jun 6 09:52:51 PDT 2009
> Indeed we were discussing this in the IRC,
> Actually it is interesting to note that the continuos function written
> as comment in newCapacity
> double mult2 = 1.0 + (size / log10(pow(newcap * 2.0,2.0)));
> does *not* have that behaviour.
> It seems to me that it is generally much better to work on the total
> memory rather than on the number of elements.
> I would use something like
> long mult = 100 + 200L / log2plus2(newcap)
> and round up
> newext = cast(size_t)((newcap * mult) / 100);
> newext += size-(newext % size);
>
> This is what I am adding in tango.
thinking more about this, given that one starts at pagesize ~4024,
log2=12 this might be too conservative, I will test a little bit more...
> One could add something that further favors large sizes, but I miss the
> rationale behind that, I would rather expect that one typically
> concatenates strings (size=1..4) and so there is more to gain by making
> that faster.
> I can also understand if someone wants to use only the number of
> elements (rather than the total size), but what was implemented wasn't
> that either.
maybe the number of elements is really the correct thing to do...
>
> If someone has some insight, or good benchmarks to choose a better
> function it would be welcome.
>
> Fawzi
More information about the Digitalmars-d
mailing list