Hi Charles, > SEXP testXptr(SEXP A) > { > arma::Mat<double> armaMat = Rcpp::as<arma::Mat<double> >(A); > Rcpp::XPtr<double> pMat(armaMat.memptr()); > return(pMat); > }
armaMat is on the stack, so the Armadillo memptr is no longer valid when you return from the testXptr function. One simple solution in your case would be to dynamically allocate with "new" [e.g. arma::mat *A = new arma::mat(...);], though I can't tell you off hand how object lifetime is managed with Armadillo objects. If you're trying to preserve a matrix across function calls in R, have you looked into bigmemory? http://gallery.rcpp.org/articles/using-bigmemory-with-rcpp/ John _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel