Sub-optimal libc's read-ahead buffering behaviour

Peter Jeremy PeterJeremy at optushome.com.au
Thu Aug 4 19:04:44 GMT 2005


On Thu, 2005-Aug-04 10:26:37 +0100, David Malone wrote:
>On Thu, Aug 04, 2005 at 05:57:11PM +1000, Peter Jeremy wrote:
>> That said, I've seen similar behaviour on other systems so it could be
>> a subtle side-effect of POSIX.
>
>There are some magic things about fseek in the C standard - I wonder
>if this could be related to them. For example (from C99) in the
>commentry on fopen:
[read/write switching]

I don't see anything there that mandates the existing behaviour.  The
existing behaviour may be a simple way to implement the requirements
but a more efficient way would seem to be to use flags to allow
read/write switching and only reload the buffer if the next I/O
operation specifies a different direction to the previous one.

>Could what stdio is doing be related to flushing ungetc?

The ungetc buffer is separate to the normal I/O buffer.  Flushing it
shouldn't require the normal I/O buffer to be re-read.

-- 
Peter Jeremy


More information about the freebsd-current mailing list