[Rcpp-devel] Segfault, is it because of iterators/pointers?
edd at debian.org
Wed Feb 12 14:20:08 CET 2014
On 12 February 2014 at 13:36, Alessandro Mammana wrote:
| Ah wait, my bad (as always T.T), I found a much simpler explanation:
Isn't it lovely when persistence pays off? ;-)
| colset <- sample(3e7-nr, 1e7)
|  "integer"
|  "double"
| So when I was unwrapping colset I allocated new memory in Rcpp to
| convert from double to integer, which was no longer valid when I went
| out of scope.
Well that is sort-of a known issue. Look for discussions of clone() in the
| I think it is a bit dangerous that you never know if you are
| allocating memory or just wrapping R objects when parsing arguments in
| Is there a way of ensuring that NOTHING gets copied when parsing
| arguments? Can you throw an exception if the type you try to cast to
| is not the one you expect?
If you don't require an (implicit) cast and you don't use clone(), nothing
gets copied. That;s how proxy objects around SEXP work.
| You might imagine that with large datasets this is important.
You can also use XPtr, and XPtr in combination with bigmemory's big.matrix,
to keep data away from R.
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel