| buffer | R Documentation |
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")
)
type |
Character. Data type: "double" (default), "integer", "logical", or "raw". |
dim |
Integer vector. Dimensions of the buffer. For a vector, specify
the length. For a matrix, specify |
init |
Initial value to fill the buffer. Default is type-appropriate
zero ( |
backing |
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
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.
segment_create for low-level segment operations,
share for read-only shared inputs
out <- buffer("double", dim = 100)
out[1:10] <- rnorm(10)
result <- out[]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.