From: Tomas Hlavaty
Subject: Q: Reading n bytes at once?
Date: 
Message-ID: <3D36D64B.99CA301F@labe.felk.cvut.cz>
Hello!

I'd like to improve the speed of my Lisp program, which reads binary
files (X0MB-X00MB long). The bottleneck is that I read the binary file
using read-byte. Is there any more suitable solution in Lisp or the only
solution is to read the file in a C function interfaced to Lisp?

Thanks

Tomas Hlavaty

From: Knut Anders Hatlen
Subject: Re: Q: Reading n bytes at once?
Date: 
Message-ID: <86r8i0divf.fsf@stjernegris.hatlen.net>
Tomas Hlavaty wrote:

> I'd like to improve the speed of my Lisp program, which reads binary
> files (X0MB-X00MB long). The bottleneck is that I read the binary
> file using read-byte. Is there any more suitable solution in Lisp or
> the only solution is to read the file in a C function interfaced to
> Lisp?

You should have a look at READ-SEQUENCE.
http://www.xanalys.com/software_tools/reference/HyperSpec/Body/f_rd_seq.htm

* (with-open-file (stream ".emacs" :element-type '(unsigned-byte 8))
    (let ((array (make-array 10 :element-type '(unsigned-byte 8))))
      (read-sequence array stream) 
      array))      

#(59 59 10 59 59 32 36 73 100 58)

-- 
Knut Anders
From: Joe Marshall
Subject: Re: Q: Reading n bytes at once?
Date: 
Message-ID: <dMDZ8.30329$_51.32475@rwcrnsc52.ops.asp.att.net>
"Knut Anders Hatlen" <········@online.no> wrote in message ···················@stjernegris.hatlen.net...
> Tomas Hlavaty wrote:
>
> > I'd like to improve the speed of my Lisp program, which reads binary
> > files (X0MB-X00MB long). The bottleneck is that I read the binary
> > file using read-byte. Is there any more suitable solution in Lisp or
> > the only solution is to read the file in a C function interfaced to
> > Lisp?
>
> You should have a look at READ-SEQUENCE.
> http://www.xanalys.com/software_tools/reference/HyperSpec/Body/f_rd_seq.htm
>
> * (with-open-file (stream ".emacs" :element-type '(unsigned-byte 8))
>     (let ((array (make-array 10 :element-type '(unsigned-byte 8))))
>       (read-sequence array stream)
>       array))
>
> #(59 59 10 59 59 32 36 73 100 58)

If this isn't fast enough, you can foreign-call MMAP.
From: Tomas Hlavaty
Subject: Re: Q: Reading n bytes at once?
Date: 
Message-ID: <3D37C61A.FAA7405A@labe.felk.cvut.cz>
Joe Marshall wrote:
> 
> "Knut Anders Hatlen" <········@online.no> wrote in message ···················@stjernegris.hatlen.net...
> > Tomas Hlavaty wrote:
> >
> > > I'd like to improve the speed of my Lisp program, which reads binary
> > > files (X0MB-X00MB long). The bottleneck is that I read the binary
> > > file using read-byte. Is there any more suitable solution in Lisp or
> > > the only solution is to read the file in a C function interfaced to
> > > Lisp?
> >
> > You should have a look at READ-SEQUENCE.
> > http://www.xanalys.com/software_tools/reference/HyperSpec/Body/f_rd_seq.htm
> >
> > * (with-open-file (stream ".emacs" :element-type '(unsigned-byte 8))
> >     (let ((array (make-array 10 :element-type '(unsigned-byte 8))))
> >       (read-sequence array stream)
> >       array))
> >
> > #(59 59 10 59 59 32 36 73 100 58)
> 
> If this isn't fast enough, you can foreign-call MMAP.

Thank you.

Tomas