if (FALSE) {
# MASTER SESSION:
# init some data and make shared
}
n = 1000
m = 100
mat = matrix(rnorm(n * m), n, m) # target matrix
y = rnorm(n) # some other constant vector in which the function should not run
namespace = "ns_retrview"
memshare::registerVariables(namespace, list(mat=mat, y=y))
if (FALSE) {
# WORKER SESSION
# retrieve the shared data and work with it
}
res = memshare::retrieveViews(namespace, c("mat", "y"))
if (FALSE) {
# res is a list of the format:
# list(mat=matrix_altrep, y=vector_altrep),
# altrep-variables can be used
# exactly the same way as a matrix or vector
# and also behave like them when checking via
# is.matrix or is.numeric.
# important: Free view before resuming
# to master session to release the variables!
}
memshare::releaseViews(namespace, c("mat", "y"))
if (FALSE) {
# MASTER SESSION
# After all view handles have been free'd, release the variable
}
memshare::releaseVariables(namespace, c("mat", "y"))
Run the code above in your browser using DataLab