Skip to content
Prev 5269 / 10988 Next

[Rcpp-devel] gc() calls destructor twice when both class and XPtr deleted

Hi Dirk --

     Thanks for the quick response. My design is (I think) textbook 
aggregation -- in my case, A is a logger class and B is an experiment 
class. The experiment calls methods from the logger, but the logger may 
be active for more than one experiment so it can't be created inside it. 
So I create the logger and pass a pointer to it into the experiment. 
There are definitely other ways to design this, but this way doesn't 
seem to be particularly unreasonable.

     The basic goal is to create a C++ object on the R side (in this 
case, the logger class) and pass it back down to the C++ side for later 
use by another C++ object (the experiment class). I thought that XPtr 
was the right way to do this (based on e.g. 
http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2011-December/003214.html), 
but I could be misunderstanding either XPtrs or the example in that 
email. If there is a different way to pass down the Rcpp class and 
unwrap it to arrive at a pointer to the underlying C++ class, it would 
be great. Best,

         Mike.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130211/410bf71a/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: postbox-contact.jpg
Type: image/jpeg
Size: 1228 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130211/410bf71a/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: compose-unknown-contact.jpg
Type: image/jpeg
Size: 770 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130211/410bf71a/attachment-0003.jpg>