[Rcpp-devel] (Very) rare segfault
Gregor Kastner
gregor.kastner at wu.ac.at
Wed Aug 20 20:57:10 CEST 2014
JJ> Yes, RNGScope isn't safe by itself. You can use it via attributes (and we
JJ> make sure to use it correctly) or you could use this pattern e.g. if you
JJ> are planning to return a NumericVector:
JJ>
JJ> NumericVector vec(20); // or whatever size, the important thing is
JJ> allocating the return SEXP before RNGScope
JJ>
JJ> RNGScope rngScope;
JJ>
JJ> // do your thing
JJ>
JJ>
JJ> return vec;
OK thanks. That's definitely worth knowing. Might be a cause for trouble for
others too, especially since misuse (i.e. other ordering) doesn't seem to show
any effects in many cases.
DE> RNGScope is not for for seed setting, it is for RNG 'state sanity'. See
DE> Section 6.3 of 'Writing R Extensions' -- worst case you can just call
DE> GetRNGstate() and PutRNGstate() by hand. Though we never had to
DE> recommend that yet.
Yep, sorry for the misuse of language. And I do understand going back to
GetRNGstate() and PutRNGstate() is a bit old school; but I can definitely
confirm that it seems to be safer than resorting do the
constructor/destuctor magic.
Best,
/g
More information about the Rcpp-devel
mailing list