Article View: comp.std.c
Article #4539Re: Circular buffering for FILEs? Why not?
From: Robert Corbett
Date: Tue, 02 Jan 1996 01:25
Date: Tue, 02 Jan 1996 01:25
36 lines
2212 bytes
2212 bytes
In article <4c9q8e$63i@access2.digex.net>, John Cochran <jdc@access2.digex.net> wrote: >In article <4c9i65$3b6@segfault.monkeys.com>, >Ronald F. Guilmette <rfg@monkeys.com> wrote: >>I have a question about the traditional implementation of buffered FILEs. >> >>From this fact I deduce that traditional implementations of the entire >>stdio set of functions _do not_ treat FILE buffers as so-called ``circular >>buffers'' but rather treat them a mere linear buffers. >> >>My question is just this... Why? >> >>Given that traditional implementations of the FILE structure include a >>``_cnt'' field, it seems to me that it would have been possible... albeit >>at a slight cost... to treat FILE buffers as circular buffers, wraping >>the value of _ptr back to the physical beginning of the buffer each time >>it was seen to have passed the physical end of the buffer. But it seems >>that nobody does this. Why not? > >Why bother? "Why bother" is the correct answer. The reasons given (which I have deleted) are correct, but not complete. A higher-level explanation might prove helpful. Circular buffering is useful when I/O and processing can be overlapped. Circular buffering allows sequential I/O to read ahead or write behind while the data already read is being processed or the next batch of data to be written is being computed. Since C has no notion of overlapped I/O and processing, circular buffering not useful in implementing the C I/O library. The underlying OS might support overlapped I/O and processing. The OS, therefore, might well be using circular buffers when dealing with sequential devices. For direct access devices, the popular buffering schemes tend to be more complex than circular buffering. Sincerely, Bob Corbett
Technical Details
Message-ID:
<4ca1ik$ffa@engnews2.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!lupa!corbettReferences:
<4c9i65$3b6@segfault.monkeys.com> <4c9q8e$63i@access2.digex.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!lupa!corbett From: corbett@lupa.eng.sun.com (Robert Corbett) Newsgroups: comp.std.c Subject: Re: Circular buffering for FILEs? Why not? Date: 2 Jan 1996 01:25:40 GMT Organization: Sun Microsystems Computer Corporation Message-ID: <4ca1ik$ffa@engnews2.Eng.Sun.COM> References: <4c9i65$3b6@segfault.monkeys.com> <4c9q8e$63i@access2.digex.net> NNTP-Posting-Host: lupa.eng.sun.com