Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!pacbell.com!ucsd!ucbvax!ulysses!kpv From: kpv@ulysses.att.com (Phong Vo[drew]) Newsgroups: comp.lang.c Subject: Re: Efficient dynamic storage question Message-ID: <14632@ulysses.att.com> Date: 21 Apr 91 16:35:27 GMT References: <32121@usc> Organization: AT&T Bell Laboratories, Murray Hill Lines: 19 In article <32121@usc>, ajayshah@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.