[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Need for scm_remember_upto_here_* in guile-2.0
From: |
Chris Vine |
Subject: |
Need for scm_remember_upto_here_* in guile-2.0 |
Date: |
Sat, 12 Sep 2015 13:27:25 +0100 |
Hi,
The guile manual suggests (section 5.5.5) that if a smob's internals
are referenced in a function after the last time that the SCM variable
representing the smob is accessed in the function,
scm_remember_upto_here_* should be used. Otherwise the suggestion is
made that the optimizer may treat the smob as expended after the last
access to its variable is made in the function, with the result that
the collector may reclaim its memory, including any internals (in the
case of the example in section 5.5.5, the smob's 'image' struct).
scm_remember_upto_here_1() does this by the simple expedient of taking
the SCM object as an argument and doing nothing, so the garbage
collector still thinks the smob is in use until then. (This is fine as
far as it goes although could perhaps be tripped up by
link-time-optimization).
However I am finding difficulty in understanding why that should be the
case, because in that example all the smob's internals are allocated
using scm_gc_malloc()/GC_MALLOC or scm_gc_malloc_pointerless()/
GC_MALLOC_ATOMIC. The garbage collector should therefore be fully
aware of those internals and be able to mark them for survival if still
in use, without any help from the programmer.
Is the point here that the example code contains an unnecessary (and
ill-advised) free function for the smob, which calls scm_gc_free() on
its internals? If so, is the point that the scm_remember_upto_here_*
functions are in practice only needed for smobs which provide their own
free function?
If so, that would further imply (in relation to the 'image' example)
that finding a live managed pointer allocated by scm_gc_malloc() in the
smob's data field (as passed when calling scm_new_smob()) does not save
the smob from collection by the garbage collector (and so its free
function being invoked by guile). Is that really the case?
Regards,
Chris
- Need for scm_remember_upto_here_* in guile-2.0,
Chris Vine <=
- Re: Need for scm_remember_upto_here_* in guile-2.0, Ludovic Courtès, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, David Kastrup, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, Mark H Weaver, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, David Kastrup, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, Ludovic Courtès, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, Chris Vine, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, Chris Vine, 2015/09/22
- Re: Need for scm_remember_upto_here_* in guile-2.0, David Kastrup, 2015/09/23
- Re: Need for scm_remember_upto_here_* in guile-2.0, Chris Vine, 2015/09/23
- Re: Need for scm_remember_upto_here_* in guile-2.0, David Kastrup, 2015/09/23