[Top][All Lists]

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

Re: [PATCH] read-file: Avoid memory reallocations with seekable files.

From: Paul Eggert
Subject: Re: [PATCH] read-file: Avoid memory reallocations with seekable files.
Date: Sun, 24 Oct 2010 17:58:38 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20101006 Thunderbird/3.1.5

On 10/24/2010 05:26 PM, Pádraig Brady wrote:

> On a related note I was wondering if we should fall back
> to increasing the buffer by +=BUFSIZ rather than *=2
> when we get ENOMEM?

I wouldn't bother, as it would lead to O(N**2) behavior,
which could well be worse than the problem that it'd cure.
(Currently it's not *=2, by the way, it's more like *=1.5.)

I found a couple of minor problems in the patch.  This comment needs to
be updated, to match the new behavior:

  /* For a regular file, allocate a buffer that has exactly the right           

since the buffer is now 1 byte "too large".  Also, this line:

            if (SIZE_MAX <= alloc_off)

should be changed to:

            if (SIZE_MAX - 2 < alloc_off)

in order to detect the overflow that now occurs when
st.st_size - ftello (stream) == SIZE_MAX - 1.  Using
it "SIZE_MAX - 2 <" rather than "SIZE_MAX - 1 <=" will
make the relationship between this "2" and the "2" in
"alloc_off + 2" more obvious to the reader.

reply via email to

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