[Rcpp-devel] Vector allocation memory problem
Dirk Eddelbuettel
edd at debian.org
Fri Apr 8 14:42:53 CEST 2011
On 8 April 2011 at 14:18, romain at r-enthusiasts.com wrote:
| Hmmm. I think you just need "i<n" instead of "i<=n" in your for construct.
==:-)
Indeed. I shouldn't mail before coffee. Here is the fixed version:
library(Rcpp)
library(inline)
src <- '
Rcpp::NumericMatrix xA(A);
int n=xA.nrow();
NumericVector dist(n);
for(int i=0;i<n;i++){dist[i]=1.0;}
return dist;'
cxxfun <- cxxfunction(sig=signature(A="matrix"),body=src,plugin="Rcpp")
## Tests.
doWork <- function(n) {
A <- matrix(0, n, n)
print(sum(dist <- cxxfun(A)))
NULL
}
doWork(20)
doWork(200)
doWork(2000)
Dirk
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list