[Rd] serialization of external pointers

Simon Urbanek simon.urbanek at r-project.org
Thu May 26 17:04:22 CEST 2011


On May 26, 2011, at 10:40 AM, Romain Francois wrote:

> Hello,
> 
> 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.

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).

Cheers,
Simon



More information about the R-devel mailing list