Skip to content

[Rcpp-devel] bigmatrix and segmentation fault due to 'memory not mapped'

2 messages · stefano iacus, Romain Francois

#
Hi everybody,

I am trying to use big.matrix from Rcpp basically to write some 
(integer) data to a matrix.

I keep getting segmentation fault due to 'memory not mapped'.
Debugging with gdb I found out that the critical point is

MatrixAccessor<int> ma(*pBigMat);

The function is declared as something like (I just followed the Gallery 
Rcpp example):

RcppExport SEXP myFun(SEXP X, SEXP Y, SEXP Z, SEXP XX, XPtr<BigMatrix> 
pBigMat)

Basically it cannot get to the correct pointer.

The really weird thing is that this error happens ONLY using the 
function built within a package

.Call('myFun',X,Y,Z,XX,bigMat at address,package='myPackage')

BUT if I use the very same code, changing just the declaration

// [Rcpp::export]
IntegerVector myFun(SEXP X, SEXP Y, SEXP Z, SEXP XX, XPtr<BigMatrix> 
pBigMat)

and then

sourceCpp('mycode.cpp')

and

myFun(X,Y,Z,XX,bigMat at address)

it works fine!

So what am I doing wrong here? Is the pointer reset somehow? But why 
only when using .Call version?

Thanks

Stefano
#
Le 15 mai 2014 ? 09:03, Stefano Calza <stecalza at gmail.com> a ?crit :
If you use a raw .Call, all your parameters have to be SEXP. 
If you want to use other parameter types, such as XPtr<BigMatrix>, you need to use attributes (i.e. sourceCpp or compileAttributes) so that it generates .Call compatible function for you. 

Romain