8 ms·
Slurping a file in Common Lisp
- qwph 18y agoEnjoyable read. I especially liked the conclusion.
- s3graham 18y agoFor 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 18y agoThe SB-POSIX package has a function that calls out to mmap: (sb-posix:mmap addr length prot flags fd offset)
- Hexstream 18y agoslurp-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.