[Openmcl-devel] make-record malloc/free question
Cyrus Harmon
ch-openmcl at bobobeach.com
Fri Aug 20 01:31:54 PDT 2004
The ivector stuff seems cool, but still leaves the responsibility of
disposing of the memory to the client. I was hoping to make classes
that wrap foreign memory access and look like lisp objects to the
client. The terminate stuff looks like the right direction and these
two approaches aren't mutually exclusive.
Thanks,
Cyrus
On Aug 19, 2004, at 2:19 PM, Andrew P. Lentvorski, Jr. wrote:
>
> 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