Every obejct will initialize twice?
Hi Rich, I just try to put RcppR6 into my own packages. This package is really inseresting!
Reading the code of RcppR6, I just learned how to use XPtr in Rcpp. oops... I missed this feature when I first read Dirk's book.
I found that RcppR6 can really speed up the loading process, and the size of package will be smaller too.
I also found that the time of initializing a new obejct was twice as much as the Modules based package, if it takes more than 1s to create a raw C++ obejct.
After reading the source code, I found that RcppR6 will initialize every obejct twice before the obejct is exported into R. If it will take a great time to initialize a raw C++ obejct, RcppR6 will be slower than Rcpp Modules, and maybe will take more internal storage too.
namespace Rcpp {
template <typename T>
SEXP wrap(const jiebaR6::RcppR6::RcppR6<T>& x) {
return x.to_R6();
}
template <> inline SEXP wrap(const jiebaR::mixseg& x) {
return wrap(jiebaR6::RcppR6::RcppR6<jiebaR::mixseg>(x));
}
//// mixseg is the class needed to be exported into R, and will take 2s to create in pure C++ code.
And the classes in C++ which I wanted to be exported into R are inherited from a class which has a private copy constructor. So if I want to use RcppR6, I need to construct a copy constructor for this class, It seems that the class must have a copy constructor if it need to be exported by RcppR6. If I use Rcpp Modules, I do not need to worry about this.
As soon as I learned XPtr, I knew a much easier way to export C++ class even without the help of R6.
Thanks.
Thanks for finding that out - this is very useful, and clearly a design problem. I'll think about how to fix this.
RcppR6 came from using XPtr (which is lovely) but you can't do much with pointers in R without providing a bunch of boilerplate - RcppR6 aims to do that boilerplate for you.
I plan on doing a lot of work with RcppR6 in the new year and will fix this then.
OK, this, p7 explains what is going on with the current version. Using an equivalent of make_shared would help, but I don't think that there is an XPtr equivalent, and writing one is probably beyond me at the moment.
I'd wondered about going through shared_ptr, but it looks like that won't work: http://stackoverflow.com/a/26220868