futureverse / futureverse/marshal
DESIGN: `clone` / `inplace` argument
- Dominant language
- R
- Stars
- 15
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
When marshaling objects that have reference semantics, having a `clone` / `inplace` parameter for the `(un)marshal` generics might be handy.
The pseudocode below illustrates a call to `marshal()`, where cloning is not necessary and another call to `unmarshal()` where it is necessary.
```r
g <- function() {
x_marshaled <- callr::r({
x <- f(...)
marshal(x, clone = FALSE)
})
x_unmarshaled <- unmarshal(x_marshaled, clone = TRUE)
y <- h(x_unmarshaled)
return(list(x_marshaled, y))
}
```
To stay on the safe side, marshal methods for objects with reference semantics should always clone by default and not modify th object that is being marshaled in-place. Because `marshal()` if often called right before sending the object to another process, it might be worth to optimize the special case where in-place modifications are allowed (or in general, the object that is being marshaled is not being further used).
Contributor guide
Assessment
This issue has not been assessed yet.