guile-user
[Top][All Lists]
Advanced

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

Re: Invoking guile procs from C in an efficient way


From: Rob Browning
Subject: Re: Invoking guile procs from C in an efficient way
Date: Tue, 26 Oct 2004 22:12:08 -0500
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Victor Morilla <address@hidden> writes:

> Why scm_permanent_object is used ? Would it be
> equivalent something like:
>
> foo()
> {
>   static SCM my_proc =
> scm_variable_ref(scm_c_lookup("my-proc"));
>   scm_apply(my_proc, argslist, SCM_EOL);
> }

It's only OK to cache the result of scm_variable_ref if you know
you'll never change the value of the variable (via set!) and want to
track that change on the C side.

Also, the scm_permanent_object (or something equivalent) is necessary
because the GC can't see static varibles.  However, if you know for
sure that the value you're storing in my_proc is bound to something on
the Scheme side that will outlast your usage of the C code above, then
you can do without the call to scm_permanent_object.

Also, as previously mentioned, you can use
scm_gc_protect/unprotect_object if you only need the object for a
limited period of time.

-- 
Rob Browning
rlb @defaultvalue.org and @debian.org; previously @cs.utexas.edu
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592  F9A0 25C8 D377 8C7E 73A4




reply via email to

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