The general semantics of the R function map to
the underlying operating system C function call.
On unix-alikes this is ‘mmap’, on Windows
similar functionality is provided by the
system call ‘MapViewOfFile’. The notable
exception is the use of the R argument file
in place of
void *addr
and int fildes
. Additionally
len
and off
arguments are
made available to the R level call, though require
special care based on the system's mmap
and are advised for expert use only.
as.mmap
allows for in-memory objects to be
converted to mmapped version on-disk. The files are
stored in the location specified by file
.
Passing an object that has an appropriate
as.mmap method will allow R objects to be automatically
created as memory-mapped object.
This works for most atomic types in R, including
numeric, complex, and character vectors. A special note
on character vectors: the implementation supports both
variable width character vectors (native R) as well as
fixed width arrays requiring a constant number of bytes per element.
The current default is to use fixed width, with variable
width enabled by setting mode=cstring()
. See as.mmap.character
for more details.
Complex data types, such as 2 dimesioned vectors (matrix)
and data.frames can be supported using appropriate
extractFUN
and replaceFUN
functions to convert
the raw data. Basic object conversion is made available
in included as.mmap
methods for boths types as of
version 0.6-3.
All mode types are defined for single-column atomic
data, with the exception of structs. Multiple column
objects are supported by the use of setting dim
.
All data is column major. Row major orientation, as well
as supporting multiple types in one object - imitating
a data.frame, is supported via the struct
mode.
Using struct
as the mode will organize the
binary data on-disk (or more correctly read data organized on disk) in
a row-major orientation. This is similar to how a row
database would be oriented, and will provide faster
access to data that is typically viewed by row.
See help(struct)
for examples of semantics as well
as performance comparisons.