Learn R Programming

bigmemory (version 2.3)

shared.big.matrix: Create a shared ``big.matrix''.

Description

Create a big.matrix in shared memory.

Usage

shared.big.matrix(nrow, ncol, type = "integer",
                init = 0, dimnames = NULL)

Arguments

nrow
number of rows.
ncol
number of columns.
type
the type of the atomic element ("integer" by default).
init
a scalar value for initializing the matrix; this cannot be a matrix or a vector of values.
dimnames
a dimnames attribute: a list of length 2 giving the row and column names respectively.

Value

  • A shared memory big.matrix is returned, described, or attached by these functions. shared.big.matrix() creates a new matrix in shared memory, while attach.big.matrix() creates the R big.matrix object referencing an existing matrix in shared memory as described by describe().

Details

A shared big.matrix object is essentially the same as a non-shared big.matrix object except the memory being managed may be shared across R sessions. These object act much like traditional R matrices. However, big.matrix objects protect the user from many of the memory-consuming pitfalls of traditional R matrices and data frames. Your system configuration may pose initial problems. The relevant configuration file is /etc/sysctl.conf, and we include a sample file in the package root. The last two options, kernel.shmmax and kernel.shmall, are the ones that are probably most important. We also include a little R script, ipc.R, which can flush out shared memory segments that sometimes persist if you segfault for some reason, or fail to exit cleanly.

See Also

bigmemory, big.matrix, or the class documentation big.matrix.

Examples

Run this code
# This example won't run on the Windows version of the package,
# and if you are reading this message you are most certainly using
# a non-Windows version.

# The example is quite silly, as you wouldn't likely do this in a
# single R session.  But if zdescription were passed to another R session
# via SNOW, NetWorkSpaces, or even by a simple file read/write,
# then the attach of the second R process would give access to the
# same object in memory.  Please see the package vignette for real examples.
z <- shared.big.matrix(3, 3, type='integer', init=3)
z[,]
dim(z)
z[1,1] <- 2
z[,]
zdescription <- describe(z)
zdescription
y <- attach.big.matrix(zdescription)
y[,]
y
z
y[1,1] <- -100
y[,]
z[,]

Run the code above in your browser using DataLab