Error: No methods applicable for generic function
#<STANDARD-GENERIC-FUNCTION STREAM-READ-BYTE> with args
(#<BIDIRECTIONAL-TERMINAL-STREAM fd 16/15 @ #x20256dca>)
of classes
(BIDIRECTIONAL-TERMINAL-STREAM)
how can I read bytes instead efficiently?
--
ricky
rgi...@surfsouth.com
On Unix, character streams and byte streams are fairly
interchangeable. Have you measured READ-CHAR is actually slower than
READ-BYTE?
If this is really the case, you could try doing a CHANGE-CLASS on your
stream to BIDIRECTIONAL-BINARY-SOCKET-STREAM. Alternatively, you can
create your own binary stream and give that as argument to the :output
key argument of RUN-SHELL-COMMAND.
--
Lieven Marchand <m...@bewoner.dma.be>
Lambda calculus - Call us a mad club
Which inefficient solutions have you tried so far? (Since you use
one of those extremely annoying invalid return addresses, I'm not
inclined to provide you with the solution I used ere the dawn of
bivalentน streams in Allegro CL.)
#:Erik
-------
น "multivalent" in recent terminology change, but it sounds silly
--
If this is not what you expected, please alter your expectations.
I don't know how to create a binary stream, could you fill me in?
(All I found were functions to make streams from existing
streams.)
If you know how I can convert a character to an integer that
would be fine too, I just thought converting every byte might be
inefficient.
>
> On Unix, character streams and byte streams are fairly
> interchangeable. Have you measured READ-CHAR is actually slower than
> READ-BYTE?
> If this is really the case, you could try doing a CHANGE-CLASS on your
> stream to BIDIRECTIONAL-BINARY-SOCKET-STREAM. Alternatively, you can
> create your own binary stream and give that as argument to the :output
> key argument of RUN-SHELL-COMMAND.
--
ricky
rgi...@surfsouth.com
> If you know how I can convert a character to an integer that
> would be fine too, I just thought converting every byte might be
> inefficient.
CHAR-CODE gets the code of a character. It's unlikely to be
inefficient compared to doing I/O.
--tim
The function char-code returns the integer code of the character.
It's essential a type-changing function, as both characters and
integers are immediate values, and at least in Allegro CL is a
simple bit-shift operation if you declare the character's type.
#:Erik
> I don't know how to create a binary stream, could you fill me in?
> (All I found were functions to make streams from existing
> streams.)
I still think you're optimizing something that will be lost in the
fringe, but one way to do it is like this:
(defun test-function ()
(let ((stream (open "/tmp/foo"
:direction :io
:if-exists :supersede
:element-type 'unsigned-byte))
(output-buffer (make-array 1024 :element-type 'unsigned-byte)))
(run-shell-command "ls" :output stream)
(file-position stream 0)
(read-sequence output-buffer stream)
(close stream)
output-buffer))
Add all apropriate declarations and this could be quite fast.
USER(35): (setf *foo* (test-function))
#(35 46 110 101 119 115 114 99 45 108 ...)
USER(39): (loop for c across *foo*
collect (code-char c))
(#\# #\. #\n #\e #\w #\s #\r #\c #\- #\l ...)
(map 'list #'char-code <sequence>)