[Rcpp-devel] Segfault error during simulation in Rcpp

Matteo Fasiolo matteo.fasiolo at gmail.com
Fri May 17 00:27:53 CEST 2013


So the error appears when we are creating a RNGScope object AND we are
allocating memory
repeatedly?
So that something like this:

library(Rcpp)

myFun <- cppFunction('void myFun(){
RNGScope scope;
}')

N <- 1e6
for (j in 1:N) {
    res <- myFun( )
}

doesn't crash because we are not allocating memory using NumericMatrix or
NumericVector?

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)
is generating random variables and allocating memory in R and then pass the
pointers to a .C function.
Sigh! :(



On Thu, May 16, 2013 at 8:11 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

>
> On 16 May 2013 at 14:49, Jonathan Olmsted wrote:
> | Several things.
> |
> | Xiao, Dirk's code gives me a segfault immediately and reliably.
> |
> | All, when I do this whole song and dance using the "old" Rcpp/inline/
> | cxxfunction approach, I don't have any issues. One obvious difference
> you can
> | see (like was mentioned) in the generated code (visibile using
> verbose=TRUE) is
> | the declaration of an RNGScope object.
> |
> | But, if the memory issue crops up when you call a C++ function (syncing
> with
> | R's RNG state) 1e6 times AND you are already writing C++ maybe this is an
> | opportunity to just put one more layer of the code into C++ and create
> only one
> | such RNGScope object?
>
> Beautiful. So we get to blame R Core after all?  ;-)
>
> Dirk
>
> --
> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
> _______________________________________________
> 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/20130516/a42d8569/attachment.html>


More information about the Rcpp-devel mailing list