

Slurping a file in Common Lisp - jdale27
http://www.emmett.ca/~sabetts/slurp.html

======
Hexstream
slurp-stream3 looks pretty sloppy...

    
    
      (defun slurp-stream3 (stream)
       (with-output-to-string (out)
         (let ((seq (make-array 1024 :element-type 'character
     			   :adjustable t
    	 		   :fill-pointer 1024)))
           (loop
            (setf (fill-pointer seq) (read-sequence seq stream))
            (when (zerop (fill-pointer seq))
    	  (return))
            (write-sequence seq out)))))
    

1\. The array doesn't need to be adjustable because he's reading no more than
1024 characters at a time.

2\. read-sequence and write-sequence ignore the fill-pointer so there's no
need for it, much less initialize it to 1024 (also :fill-pointer t would have
the same effect of initializing to the length of the vector). He's using the
fill-pointer as a variable so he should just use a simple lexical variable.

------
s3graham
For a file that big I'd probably do a mmap/MapViewOfFile (depending on how the
data were accessed of course). Anyone have a pointer on that for [SB]CL?

~~~
schtarb
The SB-POSIX package has a function that calls out to mmap: (sb-posix:mmap
addr length prot flags fd offset)

------
qwph
Enjoyable read. I especially liked the conclusion.

