Subject: RE: [Ecls-list] Foreign variables setting problem
From: "Goffioul Michael" <[email-masked]>
To: <[email-masked]>
Date: Mon, 24 Oct 2005 13:34:01 +0200
List-Id: Mailing list for users and developers <ecls-list.lists.sourceforge.net>

> On Mon, 2005-10-24 at 11:52 +0200, Goffioul Michael wrote:
> > What about si:free-foreign-data, which uses cl_dealloc(). 
> Is it correct
> > to use it on memory that has been malloc'ed? (At least when 
> ECL use its
> > internal GBC, in the other case cl_dealloc is just empty).
> 
> One should use free(). For that maybe one should add a flag in
> foreign_data, as in
> 
> struct ecl_foreign {		/*  user defined datatype  */
> 	HEADER1(malloced);	/*  allocated with malloc()?  */
> 	cl_object tag;		/*  a tag identifying the type  */
> 	cl_index size;		/*  the amount of memory allocated  */
> 	char *data;		/*  the data itself  */
> };

While trying to implement this, I just thought about a potential problem.
Imagine, your code do (with *var-string* being a foreign char* variable):

	(setf *var-string* "hello")
	(setf *var-string* "world")

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....

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?

Just a thought...

Michael.

-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.
Get Certified Today * Register for a JBoss Training Course
Free Certification Exam for All Training Attendees Through End of 2005
Visit http://www.jboss.com/services/certification for more information
_______________________________________________
Ecls-list mailing list
[email-masked]
https://lists.sourceforge.net/lists/listinfo/ecls-list