In message <2005...@gate.bitblocks.com>, Bakul Shah writes:
Start with a small array. When it gets full double it (or
grow by half if you want to waste less memory).
If I might make an observation...
You do not waste malloc'ed memory until you access it. You waste some
page table entries etc in the kernel, but the actual pages do not
become part of the memory-pressure mob-rule until you touch it the
This is a very important point which people still (after 20 years of
virtual memory systems and 10 years of phkmalloc) still do not seem
to have fully understood.
I would advice a simple doubling and a terminal realloc to cut down
to actual size.
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
ph...@FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.