[Rcpp-devel] Making objects in the C++ "side" persistent

F.Tusell fernando.tusell at ehu.es
Thu Jun 12 13:10:43 CEST 2014

El jue, 12-06-2014 a las 17:48 +0900, Martin Jakt escribió:
> Hi Fernando and list members,
> > For my purposes, I think I could use S4 objects that make C++ copies of
> > themselves at creation time, accessible via an external pointer. All
> > methods would then make use of the C++ copies for speed, and at the end
> > of the session the S4 copies that live in the R side would be saved.
> I'm wondering how you've gotten on with this. I'm struggling with a somewhat 
> similar problem in my own package. This uses the 'Rcpp modules' to provide an 
> interface to a couple of C++ functions. This works very well, but accessing 
> the objects (created by new()) after a save/reload cycle results in R 
> crashing.
> I don't really mind to lose the information within the objects and am just 
> looking for some way to avoid R trying to access invalid pointers after a 
> reload. My thought was to somehow subvert the 'save' process such that the 
> pointer address is not written. Can this be done? I tried to set the 
> serialize() function for the class, but this seems not to be used by save().
> The behaviour I would be happy with, is something similar to what you get with 
> RMySQL connections. These (understandably) get dropped between sessions, and 
> need to be recreated by calling the constructor.
> I would appreciate any advice or pointers. I've tried searching the 
> documentation for answers, but have failed to find anything that I can find.
> I'd also like to say that I _really_ appreciate Rcpp, especially the sourceCpp 
> function; it's makes R comfortable to use. Thanks to the developers.
> Martin

If losing the information is no problem, and you only want to make sure
your pointers are valid, perhaps you could add a timestamp to them when

On loading your package you would have to note the time (perhaps setting
a global variable?) and then before using each pointer check that it is


More information about the Rcpp-devel mailing list