[Rcpp-devel] Vector allocation memory problem

Dirk Eddelbuettel edd at debian.org
Fri Apr 8 15:23:55 CEST 2011


On 8 April 2011 at 13:52, Cedric Ginestet wrote:
| Thanks guys,
| 
| This is partly why I got confused with this basic mistake. Why don't I 
| get a glibc error for all sizes of the vector on my distribution? Shall 

Read up on the internet on 'out of bounds access' for arrays etc --- it is
undefined behaviour. Which is what you see.

| I try to change the default of my g++ compiler or update to a different 
| version?
| 
| Remember, I am currently using Ubuntu 10.04 with g++ 4.4.1 and R 2.12.1.

Updating to current versions is always a good idea, but it has no bearing on
your programming error and the related behaviour.

Dirk

| Cheers,
| 
| Cedric
| 
| 
| 
| On 08/04/11 13:36, Dirk Eddelbuettel wrote:
| > On 8 April 2011 at 09:12, Cedric Ginestet wrote:
| > | 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?
| >
| > Yup, look like you found a bug. Even with small size (n=20, n=30, n=40)
| > I end up with the glibc error. Nasty. We'll take a look.
| >
| > Dirk
| >
| > | 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
| >

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list