<div class="gmail_quote">On Sat, Mar 27, 2010 at 8:34 AM, yami <span dir="ltr"><<a href="mailto:yamisoe@gmail.com">yamisoe@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="gmail_quote"><div>What will happen if some_object is a data member of a 'new'ed C++ class instance? Another question, code likes following:<br> for (i=0; i<n; i++) {<br> cl_object object_from_ecl = si_safe_eval(...);<br>
}<br><br>if object_from_ecl is cached in C, how ECL knows when to gc this object?</div></div></blockquote><div><br></div><div>It has no way to find it out by itself and it will normally assume the object is lost. This is in general not a good practice, because you are coupling things which are allocated by different beasts: C++'s memory manager or ECL's.</div>
<div><br></div><div>Solutions:</div><div><br></div><div>1) Allocate the classes using the Boehm-Weiser garbage collector. That implies using a newly defined "new" and "delete" operator pairs.</div><div>
<br></div><div>2) If there are only a few classes, register the location of the pointers with ECL using</div><div> extern ECL_API void ecl_register_root(cl_object *p);</div><div><br></div><div>3) Even better, keep the objects in a lisp array and keep the array in a C++ global variable, and register this one using ecl_register_root(). Your classes can then keep pointers or indices into the array data.</div>
<div><br></div><div>4) Keep the objects in an array but store the array in a lisp global variable, with a given symbol. The symbol will not disappear if it is in a package so you can keep a pointer to the symbol</div><div>
<br></div><div>There are many more which may suit one or another problem better.</div></div><br>-- <br>Instituto de Física Fundamental, CSIC<br>c/ Serrano, 113b, Madrid 28006 (Spain) <br><a href="http://tream.dreamhosters.com">http://tream.dreamhosters.com</a><br>