On 5/30/06, Bruno Haible <[EMAIL PROTECTED]> wrote:
> + tmp = realloc (out, pos + BUFSIZ);
Quadratic runtime behaviour: if you don't have particular luck with the
realloc()
implementation, for large files, this loop will spend most of its time in
realloc(), copying memory around.
Since I write a lot of code that manipulates often largish text files,
using "mmap()" (when possible) would make the thing relatively
efficient. As noted in my code, the mmap() constraints make
that code very ugly. Even if you don't see fit to mmap, you can
still base your first allocation approximation on fstat(3). That will
save you essentially all of the extra realloc() calls. (And, yes, I
know not all fd's have a valid st_size value, so you have to cope.
Still, it eases 99.9% of use.)
In general, ease of use and efficiency imply increased complexity
of the implementation. Whatever you finally do should go all the
extra miles. :)
Cheers - Bruce