Message-ID: <19871.717.24944.682478@max.nulle.part>
Date: 2011-04-08T12:42:53Z
From: Dirk Eddelbuettel
Subject: [Rcpp-devel] Vector allocation memory problem
In-Reply-To: <CAF2284D-1387-42B7-8962-8496D674A821@r-enthusiasts.com>
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