[Openmcl-devel] ccl:with-pointer-to-ivector for simple-arrays

Vebjorn Ljosa vebjorn at ljosa.com
Fri Jun 5 04:34:56 PDT 2009


Hi

I have been using ccl:with-pointer-to-ivector for some time to pass  
vector contents to foreign code. Now I would like to do the same with  
two- and three-dimensional simple-arrays of (unsigned-byte 8) and  
(unsigned-byte 16).  (The arrays are images in cl-png.)  I have found  
solutions for the other major CL implementations, but ClozureCL remains.

Pretending that such arrays are laid out just like ivectors doesn't  
work:

(let ((a (make-array (list 2 3) :element-type '(unsigned-byte 8))))
	 (dotimes (i 6)
	   (setf (row-major-aref a i) i))
	 (ccl::without-gcing
	   (ccl:with-macptrs ((p))
	     (ccl::%vect-data-to-macptr a p)
	     (loop
		for i below 6
		collect (cffi:mem-ref p :uint8 i)))))
=> (16 0 0 0 0 0)

Could someone please explain how simple-arrays of unsigned-bytes are  
laid out in memory?  Is there a pointer that I need to follow to data  
somewhere else?

Thanks,
Vebjorn





More information about the Openmcl-devel mailing list