Here is the self-contained example I asked for.  

And yes, it crashes for me too.  So let's not create 1e6 temp matrices.
Until someone has time to debug memory management internals. Which is really
hard, so this may not get fixed for a while.  Sorry.


#!/usr/bin/Rscript

library(Rcpp)
myFun <- cppFunction('NumericMatrix myFun(NumericMatrix input, int n){
  NumericMatrix A(n, n);
  for(int Row = 0; Row < n; Row++) {
    for(int Col = 0; Col < n; Col++) {
      A(Row, Col) = input(Row, Col);
    }
  }
  return A;
}')

n <- 10
x <- 1:n^2
N <- 1e6
b <- 0
for (j in 1:N) {
    means <- matrix(x, n, n)
    res <- myFun(means, n)
    a <- res[1, 1]
    b <- b + a
}

cat(sprintf("Done, b is %d\n", b))


-- 
Dirk Eddelbuettel | [email protected] | http://dirk.eddelbuettel.com
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to