3 ms·
Historically, before mandatory locking, getc and putc have been implemented as macros, and an extra check for stream state likely mattered from a performance pe
by fweimer 2y ago
Historically, before mandatory locking, getc and putc have been implemented as macros, and an extra check for stream state likely mattered from a performance perspective.
To avoid the extra check, you don't actually need two buffers, just separate buffer pointers for reading and writing. (This is probably how most libcs implement this today.) I suppose memory was really scarce back then.
- cryptonector 2y agoSeparate non-overlapping pointers into one buffer is not that different from two buffers, notionally, but yeah.
- fweimer 2y agoThe idea is that for the non-active mode, the current/end pointers are equal, signifying that the buffer is exhausted. This forces entering the slow path, where the mode can be switched. I don't think an implementation with two active, non-empty buffers is all that useful because you can't tell which buffer's progress should be used for the file pointer adjustment in ftell.
- cryptonector 2y agoI get that. One buffer that can be maximized by the path that most needs it (read or write). I'm just saying that notionally it's two independent buffers, which solves the problem of not having to force a buffer flush between mode change. > I don't think an implementation with two active, non-empty buffers is all that useful because you can't tell which buffer's progress should be used for the file pointer adjustment in ftell. Oh interesting. The other problem is that two buffers reduces memory utilization.