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: Calling Scheme from C and Garbage Collection


Greg Harvey <Greg.Harvey@thezone.net> writes:

> I really dislike the current work around, since it is, after all, not
> much less than explicit marking.

But it is more efficient, at least given the current mark-stack system.
Take it for what it is, an optimization internal to Guile.

> I'm hoping that there's a way to avoid this without declaring every
> SCM value volatile.

I haven't followed this discussion.  I just jumped into it when I
happened to see Chris' message.

I claim that this is really not a problem.

The conservative GC is safe, regardless of the intelligence of the
compiler, as long as you follow one simple rule:

* Always refer to Scheme objects with malloced memory through their
  SCM value.

When you aren't working with Scheme objects with malloced memory,
there are no rules at all: It is safe.

An example of when the rule above apply is:

*Don't* write

  SCM* p = SCM_VELTS (v);
  x = p[i];

Instead, write

  x = SCM_VELTS (v)[i];

Is this so problematic?

/mdj

P. S. The reason why big2str has a problem is that it refers directly
to malloced memory through the pointer ds.  It doesn't need to do
this, but it is slightly more efficient.