[Rd] serialization of external pointers
romain at r-enthusiasts.com
Thu May 26 17:15:51 CEST 2011
Le 26/05/11 17:04, Simon Urbanek a écrit :
> On May 26, 2011, at 10:40 AM, Romain Francois wrote:
>> I'm looking for examples of how to handle serialization of external pointers.
>> We use external pointers intensively in Rcpp for modules and one popular request is to have persistence. And I guess we need to be able to serialize/deserialize external pointers for this.
>> Also, module objects are all instances of reference classes, so maybe that can be handled at the R level ?
> Reference classes have nothing to do with EXTPTR - they are simply built around environments and as such have no issues with serialization.
Sure. I understand that.
It just happens that our classes end up encapsulating an external
pointer, so I figured instead of dealing with this at the xp level, I
could deal with it higher up.
Sort of looking for a class specific serialization. But the comments in
serialize.c sounds like a "maybe later" answer to my question.
> As for EXTPTR, well, you can perform custom serialization (see refhook in serialize() and unserialize()), so to answer your question, yes it's easy to serialize EXPPTRs - you just have to provide functions that convert them to some string representation and back.
> So far, so good, but if you were thinking of using save()/save.image()/load() to automatically serialize references in a workspace then the bad new is you can't since there is no way to provide the hooks (that's why rJava caches serialized representation inside the object so that you can restore the pointers on load when you see a NULL pointer with a serialized cache - less ideal solution, but doable).
Yes. That's what I'm looking for. I'll check what rJava does. Thanks.
Professional R Enthusiast
+33(0) 6 28 91 30 30
|- http://bit.ly/hdKhCy : Rcpp article in JSS
|- http://bit.ly/elZJRJ : Montpellier Comedie Club - Avril 2011
`- http://bit.ly/fhqbRC : Rcpp workshop in Chicago on April 28th
More information about the R-devel