Efficient dynamic storage question
Phong Vo[drew]
kpv at ulysses.att.com
Mon Apr 22 02:35:27 AEST 1991
In article <32121 at usc>, ajayshah at alhena.usc.edu (Ajay Shah) writes:
:
: ... So the program profile is
: realloc-malloc-realloc-malloc-realloc-malloc until all
: observations are read in.
:
: Question: is it much more efficient to realloc in groups of (say)
: 100 observations at a time instead of calling realloc once for each
: observation? Realloc might well have to copy a lot of elements in the
: process of doing this, right? This could be expensive.
:
: --
Assuming that this is the only thing that your program does, it is almost
certain that lots of memory copy is going to be done. The worst part is that
with some allocator such as the circular first-fit with a roving pointer
one (the first popular malloc for UNIX systems), the above pattern of
allocation can cause severe fragmentation if the size of a row is much
smaller than the number of rows. See the paper 'In Search of a Better Malloc'
that Dave Korn and I presented at the '85 Summer Usenix conference for more details.
More information about the Comp.lang.c
mailing list