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
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
"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.
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