fd-stream buffers flushing
From: Ken Olum
Subject: Last byte of fd-stream buffers never used
To: <email address hidden>
Date: Fri, 17 Dec 2010 12:53:01 -0500
In output-wrapper in fd-stream.lisp, we have the code
`(when (<= (buffer-length obuf) (+ tail ,size)) ...
I think this test should be <, not <=. TAIL is the pointer to the
first free location, so if TAIL + SIZE = LENGTH, then we could store
SIZE bytes leaving TAIL = LENGTH, which would be OK. (Perhaps after
writing the last byte the buffer should be flushed, instead of waiting
for the next write, but that's another story.)
This result of this code is that the buffer of a character file
stream is written out after every 4095 characters, rather than every
4096, probably reducing filesystem efficiency.
I checked it in SBCL 1.0.43 on x86_64 Linux, as follows:
(defvar *test* nil)
(with-open-file (*test* "delete.me" :direction :output :if-exists :supersede)
(dotimes (i 16384)
(format t "~D " i)
(write-char #\z *Test*)))
You can see that only 4095 characters are written between flushes.