[Rd] R_PreserveObject, R_ReleaseObject : reference counting needed ?

From: Romain Francois <romain.francois_at_dbmail.com>
Date: Sat, 02 Jan 2010 11:07:03 +0100


Hello,

We are currently making lots of changes to Rcpp (see the open Rcpp mailing list if interested [1] in the details).

We are now using [2] R_PreserveObject and R_ReleaseObject to manage garbage collection instead of the PROTECT/UNPROTECT dance. This seems to work well, but I was wondering if there was documentation about it.

In particular, if we preserve the same SEXP twice (or more), should we implement some sort of reference counting ?

Reading the source (below, from memory.c) I think not, but some confirmation would help.

void R_PreserveObject(SEXP object)
{

     R_PreciousList = CONS(object, R_PreciousList); }

static SEXP RecursiveRelease(SEXP object, SEXP list)
{

     if (!isNull(list)) {
	if (object == CAR(list))
	    return CDR(list);
	else
	    CDR(list) = RecursiveRelease(object, CDR(list));
     }
     return list;

}

void R_ReleaseObject(SEXP object)
{

     R_PreciousList = RecursiveRelease(object, R_PreciousList); }

I'd also be interested if there is some ideas on the relative efficiency of the preserve/release mechanism compared to PROTECT/UNPROTECT.

Thanks,

Romain

[1] http://lists.r-forge.r-project.org/pipermail/rcpp-devel/ [2]
http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/pkg/src/RObject.cpp?rev=255&root=rcpp&view=markup

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/IW9B : C++ exceptions at the R level
|- http://tr.im/IlMh : CPP package: exposing C++ objects
`- http://tr.im/HlX9 : new package : bibtex

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sat 02 Jan 2010 - 10:14:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 02 Jan 2010 - 17:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive