This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: garbage-collection


Paul Kunysch <illume@gmx.net> writes:

> Let's assume I call gh_str02scm("data") in a c program.  This function
> returns a handle to the data.  How does the garbage-collector know
> when do delete "data" from my memory? 

The guile mark function marks everything it can find on the stack
and in other special places.  An object that has no mark will
be collected in the sweep phase.  Whenever you call a object constructor
(`scm_make_anything()') or call scm_must_malloc() directly, the
garbage collector may run.


> I suppose there is a function like "void gh_gc_unmark(SCM);"
> somewhere?


SCM data = gh_str02scm("data");
...
/* remove reference to data object */
data = SCM_UNDEFINED; /* or SCM_BOOL_F,... */

xyz_object_my_data = scm_must_malloc(...) /* may invoke gc which removes data */


> The only thing I found was a comment containing "gh_gc_mark(SCM)" in
> "guile/gh.h". Does this mean that the SCM-handles point to data that
> is "not in use" by default?

When you create your own structures and you want to store scheme
objects in them, you have to mark the objects yourself with
gc_mark or gh_gc_mark().


> I'm trying to write a server that converts its input-requests to
> SCM-data. 

Cool.  


> If all requests will stay in my memory forever I have a
> problem.  A good explanation how arbage is collected would be nice.


The garbage collector is described in data-rep.texi.  You may also
want to use smobs, look at the smob example in the docs directory.



Jost

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]