[Ecls-list] Collecting foreign data

Matthew Mondor mm_lists at pulsar-zone.net
Fri Jun 22 10:14:51 UTC 2012


On Fri, 22 Jun 2012 10:59:55 +0400
Stanislav Frolov <frolosofsky at gmail.com> wrote:

> Hi! I use ECL as an embed script for my application. I need to store a
> foreign pointer and I would like to tell gc to collect it. Well, I can
> do:
> 
> ...
> cl_object cl_data = ecl_make_pointer(new my_type);
> ...
> (some (lisp 'code (with cl_data)))
> ...
> 
> After that I can directly call back in C++ and delete cl_data:
> 
> cl_object my_type_delete(cl_object x){
>  delete (my_type*)ecl_to_pointer(x);
>  return Ct;}
> 
> But it is inconvenient in many cases. Is there a way to tell gc to
> collect cl_data and to call my_type_delete when it is deleting the
> holder of my pointer?

I'm not sure that this is exactly what you're looking for, but ECL can
be told to "finalize" an object.  We cannot predict when finalization
will take place, but the GC will eventually do it as part of its
collection process if it's no longer referenced.  See EXT:SET-FINALIZER
(or ecl_set_finalizer_unprotected(), si_set_finalizer())...

Another special thing are "weak pointers" (see EXT:MAKE-WEAK-POINTER
and EXT:WEAK-POINTER-VALUE, or si_make_weak_pointer(), etc).  The
special property of these are that unlike other references, these do
not protect the referenced objects from collection by the garbage
collector (obviously to use with caution).
-- 
Matt




More information about the ecl-devel mailing list