[Rcpp-devel] Vector allocation memory problem

Cedric Ginestet c.ginestet05 at googlemail.com
Fri Apr 8 10:12:27 CEST 2011


Hi guys,

I have encountered a reproducible error in using Rcpp, which I have 
reported below. Basically, while allocation of elements in a vector to a 
particular value works well for vectors of small sizes, this returns an 
error when the size of that vector is increased. Either it returns a 
giblc error or it hangs and never resumes. I have reproduced this error 
on two different Linux distributions (Ubuntu 10.10 and 10.04 with g++ 
4.4.1 and R 2.12.1).

####################################################
library(Rcpp)
library(inline)

src <- '
   Rcpp::IntegerMatrix 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",verbose=TRUE)

## Tests.
n <- 20; A <- matrix(0,n,n); dist <- cxxfun(A);
n <- 200; A <- matrix(0,n,n); dist <- cxxfun(A);
n <- 2000; A <- matrix(0,n,n); dist <- cxxfun(A);
*** glibc detected *** /usr/lib/R/bin/exec/R: double free or corruption 
(!prev): 0x08cfc278 ***

####################################################

Is there something that I doing wrong there?
Thank you very much for your help,
Ced


-- 
Cedric Ginestet
Centre for Neuroimaging Sciences (L3.04)
NIHR Biomedical Research Centre
Institute of Psychiatry, Box P089
Kings College London
De Crespigny Park
London
SE5 8AF
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110408/19958165/attachment.htm>


More information about the Rcpp-devel mailing list