Subject: Re: Good I/O performance
From: Erik Naggum <clerik@naggum.no>
Date: 1998/04/15
Newsgroups: comp.lang.lisp
Message-ID: <3101662069997941@naggum.no>


* Tim Bradshaw
| What about mmap?

  yeah, I _so_ want to map a string onto a file.  what I do now is this:

(defun map-file-to-string (pathname)
  "Create a string that contains all the characters of a file."
  ;;this should have used a memory mapping function
  (with-open-file (file pathname :direction :input)
    (let ((string (make-array (file-length file)
		    :element-type (stream-element-type file)
		    #+allegro :allocation #+allegro :old)))
      (if (= (length string) (read-sequence string file))
	string
	(error 'file-error
	  :pathname pathname
	  :format-control "~@<~S could not be mapped to a string.~:@>"
	  :format-arguments (list pathname))))))

  the conditionalization on Allegro CL allocates the string in such a way
  that it is not copied by the copying garbage collector, and that little
  optimization sped up my application quite noticeably.  it would be so
  cool if there was a subtype of string that was really a file on disk
  through the available operating system mechanisms.  this _may_ be
  obtained with various smart ways to return strings from some foreign
  function to Lisp, but I'm not that brave, yet.  in my dreams, one could,
  say, open the file the normal way, and then a function FILE-CONTENTS
  would return a (vector (unsigned-byte 8)) or a string that would be
  mapped onto the file.

#:Erik
-- 
  religious cult update in light of new scientific discoveries:
  "when we cannot go to the comet, the comet must come to us."