Create typed writable output buffers backed by shared memory for cross-process writes during parallel execution.
Creates a typed output buffer backed by shared memory that can be written to by parallel workers using slice assignment.
buffer(
type = c("double", "integer", "logical", "raw"),
dim,
init = NULL,
backing = c("auto", "mmap", "shm")
)An S3 object of class "shard_buffer" that supports:
Slice assignment: buf[idx] <- values
Slice reading: buf[idx]
Full extraction: buf[]
Conversion to R vector: as.vector(buf), as.double(buf), etc.
Character. Data type: "double" (default), "integer", "logical", or "raw".
Integer vector. Dimensions of the buffer. For a vector, specify
the length. For a matrix, specify c(nrow, ncol). For arrays,
specify all dimensions.
Initial value to fill the buffer. Default is type-appropriate
zero (0, 0L, FALSE, or raw(0)).
Backing type for shared memory: "auto" (default), "mmap", or "shm".
Buffers provide an explicit output mechanism for shard_map.
Instead of returning results from workers (which requires serialization
and memory copying), workers write directly to shared buffers.
Supported types:
"double": 8-byte floating point (default)
"integer": 4-byte signed integer
"logical": 4-byte logical (stored as integer)
"raw": 1-byte raw data
Buffers support slice assignment using standard R indexing:
buf[1:100] <- values
segment_create for low-level segment operations,
share for read-only shared inputs
# \donttest{
out <- buffer("double", dim = 100)
out[1:10] <- rnorm(10)
result <- out[]
# }
Run the code above in your browser using DataLab