Skip to contents

Convenience function that creates a segment, writes the data, and returns an ALTREP view.

Usage

as_shared(x, readonly = TRUE, backing = "auto", cow = NULL, path = NULL)

Arguments

x

An atomic vector (integer, double, logical, or raw)

readonly

If TRUE, prevent write access (default: TRUE)

backing

Backing type for the segment: "auto", "mmap", or "shm"

cow

Copy-on-write policy for the resulting shared vector. One of "deny", "audit", or "allow". If NULL, defaults based on readonly.

path

Optional path (mmap backing) or name (shm backing) for the underlying segment. When NULL (default) an anonymous temporary segment is created; when supplied, the segment is created with that name so it can be reopened via segment_open() in other processes.

Value

An ALTREP vector backed by shared memory

Examples

# \donttest{
x <- as_shared(1:100)
is_shared_vector(x)
#> [1] TRUE

y <- x[1:10]
is_shared_vector(y)
#> [1] TRUE
# }