<html><body bgcolor="#FFFFFF"><div>Hmmm. I think you just need "i&lt;n" instead of "i&lt;=n" in your for construct.</div><div><br></div><div>Romain<br><br><div><br></div></div><div><br>Le 8 avr. 2011 à 10:12 AM, Cedric Ginestet &lt;<a href="mailto:c.ginestet05@googlemail.com">c.ginestet05@googlemail.com</a>&gt; a écrit&nbsp;:<br><br></div><div></div><blockquote type="cite"><div>

    Hi guys, <br>
    <br>
    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). <br>
    <br>
    ####################################################<br>
    library(Rcpp)<br>
    library(inline)<br>
    <br>
    src &lt;- '<br>
    &nbsp; Rcpp::IntegerMatrix xA(A);<br>
    &nbsp; int n=xA.nrow();<br>
    &nbsp; NumericVector dist(n);<br>
    &nbsp; for(int i=0;i&lt;=n;i++){dist[i]=1.0;}<br>
    &nbsp; return dist;'<br>
    cxxfun &lt;-
cxxfunction(sig=signature(A="matrix"),body=src,plugin="Rcpp",verbose=TRUE)<br>
    <br>
    ## Tests.<br>
    n &lt;- 20; A &lt;- matrix(0,n,n); dist &lt;- cxxfun(A); <br>
    n &lt;- 200; A &lt;- matrix(0,n,n); dist &lt;- cxxfun(A); <br>
    n &lt;- 2000; A &lt;- matrix(0,n,n); dist &lt;- cxxfun(A); <br>
    *** glibc detected *** /usr/lib/R/bin/exec/R: double free or
    corruption (!prev): 0x08cfc278 ***<br>
    <br>
    ####################################################<br>
    <br>
    Is there something that I doing wrong there? <br>
    Thank you very much for your help, <br>
    Ced<br>
    <br>
    <br>
    <div class="moz-signature">-- <br>
      <div class="moz-signature"><font face="Times" size="3">
          Cedric Ginestet <br>
          Centre for Neuroimaging Sciences (L3.04) <br>
          NIHR Biomedical Research Centre <br>
          Institute of Psychiatry, Box P089 <br>
          Kings College London <br>
          De Crespigny Park<br>
          London <br>
          SE5 8AF <br>
        </font>
      </div>
    </div>
  

</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Rcpp-devel mailing list</span><br><span><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a></span><br><span><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></span><br></div></blockquote></body></html>