[Rcpp-devel] Garbage collection PreserveObject.
Dirk Eddelbuettel
edd at debian.org
Sun Jan 24 01:06:41 CET 2010
Houston, we have lift-off. We have come full circle. Our use of preserve /
release followed Simon's answers to your questions on r-devel.
On 24 January 2010 at 00:44, Guillaume Yziquel wrote:
| I recently noticed that the garbage-collection interfacing toping has
| been quite active at the beginning of the month on this list, so I'm
| asking here. My question concerns essentially my OCaml binding, but I'll
| try to make it as language agnostic as possible to somehow stay within
| the scope of this list.
You are a nautical mile and a half off-topic for 'rcpp-devel', but we don't
mind. We only charge after the third question. Just kidding.
| Two questions:
|
| -1- From what I gathered, it is fine to issue two PreserveObject
| statements on the same SEXP, and then two ReleaseObject afterwards. It
| seemed to me that reference counting was not needed, from my
| understanding of the past discussion. Am I wrong?
I think you are right. We simply the object along, but AFAIK R just flips a
bit:
void preserve(){ if( m_sexp != R_NilValue ) R_PreserveObject(m_sexp) ; }
void release() { if( m_sexp != R_NilValue ) R_ReleaseObject(m_sexp) ; }
| -2- Once you have, in your C/C++ code, obtained a pointer to a SEXP from
| R, do you need to PROTECT it, then do a PreserveObject, then UNPROTECT
| it? Or is PreserveObject simply fine? (I guess so, but I'm damn unsure).
More the latter, but it is complicated. We had replaced all PROTECT /
UNPROTECT calls with preserve / release but we needed to go back for some
reason. Romain has the gory details.
Dirk
--
Three out of two people have difficulties with fractions.
More information about the Rcpp-devel
mailing list