Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!usc!alhena.usc.edu!ajayshah From: ajayshah@alhena.usc.edu (Ajay Shah) Newsgroups: comp.lang.c Subject: Efficient dynamic storage question Message-ID: <32121@usc> Date: 20 Apr 91 20:17:23 GMT Sender: news@usc Organization: University of Southern California, Los Angeles, CA Lines: 24 Nntp-Posting-Host: alhena.usc.edu Originator: ajayshah@alhena.usc.edu 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@usc.edu The more things change, the more they stay insane. _______________________________________________________________________________