Efficient dynamic storage question

Ajay Shah ajayshah at alhena.usc.edu
Sun Apr 21 06:17:23 AEST 1991


I have a program in which a matrix is allocated dynamically.
Every time I see an observation (which is a row in the matrix), I
realloc the matrix (which is float **) to contain one more row
(one more float *).  Then I malloc the row and fill up it's
elements.

These realloc calls are not interspersed with any *other* dynamic
memory activity.  I start building this matrix and
single-mindedly read observations till it takes it's final
shape.  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.

-- 
_______________________________________________________________________________
Ajay Shah, (213)734-3930, ajayshah at usc.edu
                             The more things change, the more they stay insane.
_______________________________________________________________________________



More information about the Comp.lang.c mailing list