Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DESIGN: clone / inplace argument #12

Open
sebffischer opened this issue Feb 22, 2024 · 0 comments
Open

DESIGN: clone / inplace argument #12

sebffischer opened this issue Feb 22, 2024 · 0 comments

Comments

@sebffischer
Copy link

sebffischer commented Feb 22, 2024

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.

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

@sebffischer sebffischer changed the title DESIGN: clone argument DESIGN: clone / inplace argument Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant