From: Andras S. <as...@ma...> - 2006-10-27 13:10:47
|
Following Juho Snellman's nicely commented example on http://paste.lisp.org/display/27891 I tried to write out/mmap in arrays on both 32 and 64 bit sbcl (both on Linux). It went smoothly on x86, but on x86_64 I get the following: (require 'sb-posix) (defvar *a*) (defun create-lisp-mem-from-array (array file) (declare (optimize (speed 1))) (with-open-file (map-file file :direction :output :if-exists :supersede :element-type '(unsigned-byte 64)) ;; Header (write-byte sb-vm::simple-array-unsigned-byte-60-widetag map-file) ;; Array size placeholder (write-byte 8 map-file) (loop for in across array with count = 0 do (let ((data (ash in sb-vm::n-fixnum-tag-bits))) (incf count) (write-byte data map-file)) finally (file-position map-file 1) (write-byte (ash count sb-vm:n-fixnum-tag-bits) map-file)))) (defun load-lisp-mem (map-file variable) (with-open-file (file map-file) (let* ((sap (sb-posix:mmap nil (file-length file) sb-posix:prot-read sb-posix:map-private (sb-impl::fd-stream-fd file) 0)) (addr (logior (sb-sys:sap-int sap) sb-vm:other-pointer-lowtag))) (setf (symbol-value variable) (sb-kernel:make-lisp-obj addr)) (values)))) CL-USER> (create-lisp-mem-from-array #(9 8 7 6) "map") NIL CL-USER> (load-lisp-mem "map" '*a*) ; No value CL-USER> (typep *a* 'array) NIL and the value of *a* is garbage. $ od map 0000000 000000 000000 000000 133000 000000 000000 000000 020000 0000020 000000 000000 000000 044000 000000 000000 000000 040000 0000040 000000 000000 000000 034000 000000 000000 000000 030000 0000060 (sbcl is 0.9.17 binary downloaded from sf.) What am I missing? Andras |