[Ecls-list] Collecting foreign data

Stanislav Frolov frolosofsky at gmail.com
Fri Jun 22 11:06:02 UTC 2012


2012/6/22, Matthew Mondor <mm_lists at pulsar-zone.net>:
> 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
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Ecls-list mailing list
> Ecls-list at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ecls-list
>

Thank you, Matt! I just miss finalization section in the ECL manual.




More information about the ecl-devel mailing list