Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question on streams and buffering for acl5/linux

3 views
Skip to first unread message

Steve Gonedes

unread,
Dec 15, 1998, 3:00:00 AM12/15/98
to

Anyone know if it's possible to turn off the buffering on an output
character stream in acl5 for linux? I took a quick look at things, but
they seem a bit too hairy to poke at.

I was playing around with (slot-value stream 'EXCL::BUFFER) and the
other things listed in EXCL::*STREAM-FIXED-SLOTS*, but I feel a bit
uneasy about trying to change any of these values directly.

I also saw EXCL::STREAM-BUFFER-SIZE, but don't know how to use it and
I fear that it may influence other things that I wouldn't have
expected or desired.

Also, does anyone have a non-consing method for writing fixnums to a
character stream? Right now I am using EXCL::PRINT-FIXNUM, which seems
to work well, but it's probably not the best idea to use unexported
functions - especially when I have no clue as to what they're supposed
to do. I'd like to think that print-fixnum and excl::whitespace-char-p
will do as they say - but I don't really never know for sure.

The problem with using digit-char is the number 10. I would also
prefer not to use division or any of the pretty-printing facilities.
Worst comes to worse I could always use prin1, but this seems like a
rather involved way to print a number to a stream.

I would cache the numbers, but this would also involve some lookup
overhead not to mention a large amount of memory that could otherwise
be free for more important purposes.

Thanks in advance for any responses.


Erik Naggum

unread,
Dec 16, 1998, 3:00:00 AM12/16/98
to
* Steve Gonedes <jgon...@worldnet.att.net>

| Anyone know if it's possible to turn off the buffering on an output
| character stream in acl5 for linux? I took a quick look at things, but
| they seem a bit too hairy to poke at.

(defclass unbuffered-stream () ())

(defmethod stream-write-char :after ((stream unbuffered-stream) char)
(declare (ignore char))
(force-output stream))

(defmethod stream-write-string :after ((stream unbuffered-stream) string
&optional start end)
(declare (ignore string start end))
(force-output stream))

now all you need to do is to create a subclass of unbuffered-stream and a
"real" stream. you can either do this a priori by figuring out which
stream type you will open and use the :CLASS argument to OPEN, or you can
do it a posteriori by creating the class at run-time.

(defun make-stream-unbuffered (stream)
"Modify stream so that it does not buffer its data on output."
(let* ((class-list (list 'unbuffered-stream (type-of stream)))
(name (with-standard-io-syntax (format nil "~{~A~^+~}" class-list)))
(symbol (intern name #.*package*))
(class (or (find-class symbol nil)
(clos:ensure-class symbol :direct-superclasses class-list))))
(change-class stream class))
stream)

the following test code will show what's going on.

(let ((old-class (class-of *standard-output*)))
(fresh-line)
(dotimes (i 10) (write-char #\.) (sleep 1))
(force-output)
(make-stream-unbuffered *standard-output*)
(fresh-line)
(dotimes (i 10) (write-char #\.) (sleep 1))
(change-class *standard-output* old-class))

there may be other ways, but I've fallen love with this solution, which I
use for a lot of _very_ different purposes, and which doesn't involve
low-level hackery with stream internals.

#:Erik
--
man who cooks while hacking eats food that has died twice.

0 new messages