Question

The bigmemory package in R provides a class, big.matrix which stores a matrix in memory that can be shared across R sessions as some sort of C++ object, returning a pointer to the R language.

For example:

library(bigmemory)
> a <- as.big.matrix(matrix(0, 5, 5))
> a
An object of class "big.matrix"
Slot "address":
<pointer: 0x24ae350>

Using more functions from the bigmemory package i can then write out a short description of the matrix to file, open up another R session, and access the matrix in memory from that new R session.

From R you can also call C/C++ code using the .Call() or .C().

I would like to implement some functions in either C or C++ (I am more familiar with C) that will run on this matrix in shared memory, but I have no idea how to go about this.

Given an address in memory, along with known sizes can I access an double[][] in C? or am I completely off track?

Was it helpful?

Solution

Ok luckiliy for you Dirk Eddelbuettel and Romain Francois wrote an awesome tool called Rcpp that will do all the (very) hard work for you. Install the package, read the vignettes et enjoy reusing all the example code available on Rcpp Gallery

There is even an example of how to use bigmemory in conjunction with Rcpp here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top