<div dir="ltr">So the error appears when we are creating a RNGScope object AND we are allocating memory <div>repeatedly?</div><div>So that something like this:</div><div><br></div><div><div>library(Rcpp)</div><div><br></div>
<div>myFun <- cppFunction('void myFun(){</div><div>RNGScope scope;</div><div>}')</div><div><br></div><div>N <- 1e6</div><div>for (j in 1:N) {</div><div>    res <- myFun( )</div><div>}</div><div><br></div>
<div style>doesn't crash because we are not allocating memory using NumericMatrix or NumericVector?</div><div style><br></div><div style>In any case I can't move all my code to C++, so maybe the easiest thing to do for my original problem (given my limited expertise)</div>
<div style>is generating random variables and allocating memory in R and then pass the pointers to a .C function. </div><div style>Sigh! :(</div><div> </div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Thu, May 16, 2013 at 8:11 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
On 16 May 2013 at 14:49, Jonathan Olmsted wrote:<br>
| Several things.<br>
|<br>
| Xiao, Dirk's code gives me a segfault immediately and reliably.<br>
|<br>
| All, when I do this whole song and dance using the "old" Rcpp/inline/<br>
| cxxfunction approach, I don't have any issues. One obvious difference you can<br>
| see (like was mentioned) in the generated code (visibile using verbose=TRUE) is<br>
| the declaration of an RNGScope object.<br>
|<br>
| But, if the memory issue crops up when you call a C++ function (syncing with<br>
| R's RNG state) 1e6 times AND you are already writing C++ maybe this is an<br>
| opportunity to just put one more layer of the code into C++ and create only one<br>
| such RNGScope object?<br>
<br>
</div>Beautiful. So we get to blame R Core after all?  ;-)<br>
<span class="HOEnZb"><font color="#888888"><br>
Dirk<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</div></div></blockquote></div><br></div>