simplemmap: Simple Memory-Mapped Vectors

Description Usage Arguments Details Value Author(s) Examples

Description

Create vectors with data in a memory-mapped file.

Usage

1
2
3
mmap(filename, type = c("double", "integer", "int"), ptrOK = TRUE,
     wrtOK = FALSE, serOK = TRUE)
munmap(x)

Arguments

filename

character; name of the file to be memory-mapped.

type

character; the binary data type of the elements in the file.

ptrOK

logical; whether the data pointer should be accessible.

wrtOK

logical; whether modifying the file is allowed.

serOK

logical; whether the object should be serialized as an mmaped file.

x

a memory-mapped object

Details

mmap creates vector with data in a specified memory-mapped file. The type argument specifies the binary element type in the file; for now only C double and int are supported.

If ptrOK is true, then C code requesting the data pointer will succeed, which means all C code written to work with R vectors should work, but may cause large allocations for result objects if the file mapped file is large. If ptrOK is false, then C code written to use the data pointer will fail; only C code written to access individual elements or blocks will succeed. Code for basic summary methods and subsettin has been rewritten to access data only by elements or blocks.

The file is opened read-only if wrtOK is false. In this case the vector is marked as not mutable and will be duplicated before assignments are committed. Attempts by C code to write to the data will produce a segmentation fault. If wrtOK is true, then the file is opened for reading and writing, and an assignment that would modify a standard vector in place will modify the file.

A vector created with serOK false is serialized as an ordinary vector, which will create a very large serialization if the mapped file is large. A vector created with ptrOK true is serialized by recording the file name and data type as specified to mmap in the serialization, and unserializing will attempt to recreate the memory mapping. If this fails, unserialize will issue a warning and return a zero-length vector.

Value

A vector of the specified type with data in a memory-mapped file.

Author(s)

Luke Tierney

Examples

1
2
3
4
5
6
7
8
tmp <- tempfile()
x <- runif(1000)
writeBin(x, tmp)
y <- mmap(tmp)
head(x)
head(y)
munmap(y)
unlink(tmp)

ltierney/Rpkg-simplemmap documentation built on May 21, 2019, 8:41 a.m.