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

Dirk Eddelbuettel edd at debian.org
Mon Jun 16 14:12:53 CEST 2014


Hi Martin,

On 16 June 2014 at 14:59, Martin Jakt wrote:
| (sorry Dirk, I forgot to include the mailing list in my previous posting,
| so here is another copy).

No worries.

| I've not yet found a solution to my problem, but have been trying to get my 
| head around some of the magic that Rcpp does, and have a few questions I'd 
| appreciate a pointer to.
| 
|  
| > | 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().
| > I think this is the right route.  And we now have access to serialize() from
| > the C/C++ side (via the small package RApiSerialize which I used in
| > RcppRedis). It should not be too hard to move towards something like
| > saveRDS/readRDS. Maybe you can experiment with explicitly deserialization
| > of the 'payload' of your object, and then recreate it?
| > 
| 
| RApiSerialize looks nice, but how can you get the save() function to call it 
| (or any other serialize function)? From what I can work out save() doesn't 
| seem to make use of serialize functions, but instead uses it's own 
| serialization.

But "it's own serialization" (when you refer to R) is precisely what
RApiSerialize offers.  

The problem was that what was in R itself was not accessible to usus at the
package level.  The RApiSerialize package offers you the very code R uses
(via a code copy, sadly that is the best we can do here).  

Actually opening, reading, writing, closing, ... a file on the serialized
data should now be possible with standard library facilities.  The
combination is what I suggested, and it should allow us to duplicate what
saveRDS / readRDS do.

Ok?

| (The following is a bit on the long side, but is primarily me describing what 
| I think is going on, to hopefully have any gross misunderstandings pointed 
| out.)

[ Chopping generously ]

| I'm trying to understand how that works, but can't find anything that seems 
| relevant. Do you have any suggestions as to where I can find documentation for 
| this behaviour (eg. does '$' have special meaning here?).
| 
| What I'd like is simply to have the object$function() first check the value of 
| .xData$pointer, to make sure it is not null before proceeding. But can't 
| really get any further without understanding what Rcpp Module is doing.

Like many of the internals, it is mostly undocumented.  Romain wrote most of
it, but later decided to walk away from it.  

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list