[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-devel
Subject:    Re: [Rd] serialization for external pointers
From:       Simon Urbanek <simon.urbanek () r-project ! org>
Date:       2013-11-17 3:09:48
Message-ID: 865E17BF-9ABD-47D7-ADC4-1D4384BC09FC () r-project ! org
[Download RAW message or body]

On Nov 16, 2013, at 8:30 AM, Romain Francois <romain@r-enthusiasts.com> wro=
te:

> Hello,
> =

> Are there any recipe to handle serialization / deserialization of externa=
l pointers.
> =

> I'm thinking about something similar in spirit to the way we handle final=
ization of external pointers.
> =


See refhook in serialize/unserialize.


> Currently, if we create an external pointer, save the session, quit R, th=
en load the session, we get a null pointer.
> =


Saving the session is a different story than serialization, because it also=
 involves loading the right code in addition to the data and you cannot use=
 refhooks. I recall discussing this with Luke a few years ago, and the main=
 problem is that R has no way of knowing what is needed to call the particu=
lar hooks, because the package is not even loaded, so it cannot install hoo=
ks. AFAIR the net result was that the proper way to do it is to handle the =
NULL pointer code when you first access the pointer  to restore the object =
based on additional info that you store in the object. E.g. , in rJava we s=
tore the Java serialization of the object so it can be restored on first us=
e of the new session.

One piece that is still missing it the ability to set a hook to update the =
save object on save() - since we don=92t necessarily want to add the extra =
information every time the object is created or the serialization may becom=
e stale over time. That would still be very useful to add =85

Cheers,
Simon


> One way I'm thinking of is to have an environment in the "protected" part=
 of the xp, then have an active binding there, since apparently active bind=
ings:
> - are "get" during serialization
> - lose their active ness when reloaded:
> =

> $ R
> [...]
> > f <- local( {
> +     x <- 1
> +     function(v) {
> +        if (missing(v))
> +            cat("get\n")
> +        else {
> +            cat("set\n")
> +            x <<- v
> +        }
> +        x
> +     }
> + })
> > makeActiveBinding("fred", f, .GlobalEnv)
> > bindingIsActive("fred", .GlobalEnv)
> [1] TRUE
> >
> > q("yes")
> get
> get
> =

> =

> romain@naxos /tmp $ R
> [..]
> > fred
> [1] 1
> > bindingIsActive("fred", .GlobalEnv)
> [1] FALSE
> =

> Is this possible ? Is there any other hook to handle serialization, unser=
ialization of external pointers ?
> =

> Romain
> =

> -- =

> Romain Francois
> Professional R Enthusiast
> +33(0) 6 28 91 30 30
> =

> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> =


______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic