Re: Calling a function when a something is garbage collected.

Camm Maguire <[email protected]>
Newsgroups gmane.lisp.gcl.devel
Message-ID <[email protected]>
Greetings!

Grégory Vanuxem <[email protected]> writes:

> Hello,
>
>
> My question is in object, when the garbage collector releases memory
> from a variable for example does GCL allow to add a "hook" function to
> do some other things. Namely I also need to release memory in another
> place not known to the garbage collector. Here is a piece of code for
> other CL implementations:
>
> ; TODO: add Clozure CL 'terminate'
> (defun make_jlref (val type)
>      (let* ((ret (make-instance 'jlref :val val :type type))
>             (hash (write-to-string (sxhash ret) :base 16)))
>         #+:lispworks (flag-special-free-action hash)
>         #+:cmu (ext:finalize ret (lambda () (free_jlref hash)))
>         #+:sbcl (sb-ext:finalize ret (lambda () (free_jlref hash)))
>         #+:allegro (excl:schedule-finalization ret (lambda ()
> (free_jlref hash)))
>         (setf (jlrefId ret) hash)
>         ret))
>

I do not believe we have such a feature yet, though there are stubs in
the code and we could add one.  I am confused though, what do you mean
'not known to the garbage collector'?  Is this malloc/free memory
allocated in some inlined C code?  Such memory *is* known to our garbage
collector (as is the output of write-to-string), though I suppose some
hook could automate the call to free.  Why not just add a slot :hash to
'jlref and let the GC do its thing?


> And another question, where can I find documentation for calling C
> from GCL Common Lisp?

The original defentry, clines, and defcfun are documented in the gcl-si
info page, but in 2.7 we have a much more capable defdlfun which enable
runtime and persistent access to new external shared library functions.
I will write this up, but I believe it might have been discussed in the
mailing list before.

Take care,


>
> Regards,
> - Greg
>
>
>
>

-- 
Camm Maguire			     		    [email protected]
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.