[Openmcl-devel] make-record malloc/free question

Andrew P. Lentvorski, Jr. bsder at mail.allcaps.org
Thu Aug 19 14:19:25 PDT 2004


On Aug 19, 2004, at 11:34 AM, Cyrus Harmon wrote:

>
> So I see the malloc call in make-record in macros.lisp. Is there a 
> corresponding free call somewhere? The reason I ask is that I'm trying 
> to (see previous posts) use the MOP to automagically wrap foreign 
> structures to objects with slots and I can see where to malloc storage 
> for internal buffers and the like, but I can't see the MOP hooks for 
> free, which got me wondering how make-record does it. I suppose all of 
> this works for stack allocated memory, but I don't see how things that 
> get malloc'ed in make-record get freed.

Things *can* be placed on the heap rather than the stack.  This is 
probably especially important if you want the objects to have a 
lifetime exceeding a single stack frame.  The way to do this is to use 
ccl::%make-heap-ivector.  I use a pair of helpers to handle this:

;; make-heap-ivector courtesy of Gary Byers
(defun make-heap-ivector (element-count element-type)
   (let* ((subtag (ccl::element-type-subtype element-type)))
     (unless (= (logand subtag target::fulltagmask)
                target::fulltag-immheader)
       (error "~s is not an ivector subtype." element-type))
     (let* ((size-in-bytes (ccl::subtag-bytes subtag element-count)))
       (ccl::%make-heap-ivector subtag size-in-bytes element-count))))

;; dispose-heap-ivector created for symmetry
(defmacro dispose-heap-ivector (a mp)
   `(progn
      (ccl::%dispose-heap-ivector ,a)
      ;; Demolish the arguments for safety
      (setf ,a nil)
      (setf ,mp nil)))

I thought I submitted a tutorial on how to use these a while ago, but I 
guess my memory is faulty.

-a






More information about the Openmcl-devel mailing list