On Mon, 31 Aug 2020 08:39:56 +0200, Otto Moerbeek wrote:

> 1. I do not put high pages of shrinking reallocs into to cache, but
> directly unmap.
>
> 2. For small shrinking reallocs realloc become a no-op. Pro: no
> syscalls at all, cons: the actual allocation is larger, so less
> overflow detection. So I do not do this if guard pages are active or
> the reduction is larger than the cache size.

I think this strikes a good balance.  It is a common pattern to
preallocate an estimated amount and then use realloc() to shrink
it once the actual data has been stored.  If that buffer is later
enlarged, you can get the kind of behavior your test program exhibits.

Taking advantage of the sparse address space is smart and as 64-bit
is now the norm, that space is even sparser.

 - todd

Reply via email to