[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gnulib] strfile: new module

From: Bruce Korb
Subject: Re: [bug-gnulib] strfile: new module
Date: Tue, 30 May 2006 13:24:12 -0700

On 5/30/06, Bruno Haible <address@hidden> wrote:
> +    tmp = realloc (out, pos + BUFSIZ);

Quadratic runtime behaviour: if you don't have particular luck with the 
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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]