[Rcpp-devel] Making objects in the C++ "side" persistent
Martin Jakt
mjakt at z2.keio.jp
Thu Jun 12 10:48:16 CEST 2014
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
--
Martin Jakt
Department of Systems Medicine
Mitsunada Sakaguchi Laboratory
Keio University School of Medicine
More information about the Rcpp-devel
mailing list