library: dynamic buffer management even more efficient
authorJim Warner <james.warner@comcast.net>
Sun, 14 Apr 2013 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Tue, 23 Apr 2013 22:29:22 +0000 (08:29 +1000)
commit95d0136281ec00c68e2994d708fec4dd28275453
treea722ead9967d72be30260274796c65ee0f0a1d11
parentd16fd8e4629cc4ea2cfc0954762079cbdaa544d5
library: dynamic buffer management even more efficient

One recent patch to dynamic buffer management involved
over-allocating the buffer increase to lessen calls to
xrealloc. That was successful, but the actual increase
amount did not attempt to optimize size or alignments.

With this commit, we'll copy an approach recently used
by the top program and round up buffer sizes to 1 KiB.
More importantly, while buffers are quickly reaching a
KiB optimum multiple, no memcpy will ever be employed!

To illustrate just how effective top's algorithm would
be, just change the initial and subsequent allocations
from the current 1024 bytes to just a single byte then
add an fprintf.  Those one byte reallocations while on
the way to optimum buffer size will be a one-time cost
and won't represent any recurring performance penalty.

( gosh, that top program *must be* one fart smeller, )
( or was that a smart feller, i can't remember which )

Reference)s):
commit 6d605f521c54a7011b7a255762621febda4f67e8
commit a45dace4b82c9cdcda7020ca5665153b1e81275f

Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/readproc.c