[Ecls-list] Foreign variables setting problem

Goffioul Michael goffioul at imec.be
Mon Oct 24 05:08:00 UTC 2005


> On Mon, 2005-10-24 at 13:34 +0200, Goffioul Michael wrote:
> > On the first SETF, CFFI will allocate a foreign string and 
> set *var-string*
> > to point to it. The second SETF will do the same, without 
> deallocating the
> > string "hello". To deallocate it, you would have to create 
> a foreign-data
> > object pointing to the same address as *var-string* and 
> then free it, this
> > looks tricky....
> 
> But all CFFI users will have this problem, won't they? I will 
> pass this
> further to their mailing list.

That's also my feeling, although I don't know how other LISPs
handle foreign memory.

> > Wouldn't it be easier to tell the GC to consider the 
> foreign variable as a
> > potential pointer reference to avoid the memory pointed by 
> it from being
> > collected?
> 
> This can be done. As a note to ourselves, we have to keep in mind that
> the number of roots is limited due to an implementation restriction in
> the Boehm GC that can be worked around in the future.

Note that looking at CFFI implementation of foreign vars and the one built
in ECL, I think this problem only occurs in CFFI. In ECL, the DEF-FOREIGN-VAR
macro stores a foreign-data object as a symbol property, hence the memory
pointed by the foreign var is always referenced from the LISP world.
In CFFI implementation, the foreign-data object is recreated on each read/write
access, without keeping a static reference.

Michael.




More information about the ecl-devel mailing list