[Rcpp-devel] Vector allocation memory problem
romain at r-enthusiasts.com
romain at r-enthusiasts.com
Fri Apr 8 14:18:08 CEST 2011
Hmmm. I think you just need "i<n" instead of "i<=n" in your for construct.
Romain
Le 8 avr. 2011 à 10:12 AM, Cedric Ginestet <c.ginestet05 at googlemail.com> a écrit :
> 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
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110408/1b7fb4f6/attachment.htm>
More information about the Rcpp-devel
mailing list