guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ application linked with guile dos not quite


From: Brett Viren
Subject: Re: C++ application linked with guile dos not quite
Date: Tue, 18 Jun 2002 10:45:29 -0400

Hilaire Fernandes writes:
 > I do not use any scm_ methods actualy, I do not know anything about
 > them. I do not know if guile use it internaly then wait for it to be
 > unprotected.

I don't think there is ever a time that you must call
scm_unprotect_object() unless you explicitly called
scm_protect_object().

 > Well I am wondering what is for scm_protect_object().

You would only need scm_protect_object() on any SCM if two cases are
met:

1) you store the SCM in your C/C++ code for multiple calls to gh_ or
scm_ functions (ie, any time that a garbage collection might happen).

2) If there is any chance that all internal references to the SCM will
disappear.

Since garbage collection looks at reference counts, if your C/C++ code
is still referring to an SCM, but nothing on the guile side is, then
the ref count can go to zero and the GC thinks it's okay to reap the
SCM (since it doesn't know about your C/C++ reference).  The
protect/unprotect just increments/decrements the ref count.

 > Is there some special procedure to free memory from a SCM object?
 > For example the value returned by a call to guile procedure?

Not that I know of.  I have always done things via
scm_(un)protect_object().  

BTW, you can force a garbage collection via scm_gc().  Durring
debugging I would call this once per "cycle" of my program.  This
greatly slowed things down, but it will trigger a SegV immediately so
it is easier to know when something is going wrong.

Again, I am no expert, but since the experts seem to be quiet today, I
hope this helps.

-Brett.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]