[Rcpp-devel] Rcpp 0.10.0

Darren Cook darren at dcook.org
Thu Nov 15 01:02:02 CET 2012


> so when the object returns from this as, a copy is involved. We return a
> T, not a T*, or a T&

I wonder if this gets optimized away, though? E.g.

http://blog.knatten.org/2011/08/26/dont-be-afraid-of-returning-by-value-know-the-return-value-optimization/

Definitely worth profiling and/or looking at the assembly before any
hard manual optimization.

Darren

Fuller quoting, for context:
> This is complicated. For the moment I think copies are involved often.
> But we have opportunities to recognize that we don't need to make copies.
> 
> For example :
> 
> void foo( const SomeClass& x ) ;
> 
> at the moment, in order to invoke the function, we essentially call :
> 
> as<SomeClass>
> 
> which goes down to :
> 
> /** handling T such that T is exposed by a module */
> template <typename T> T as(SEXP x,
> ::Rcpp::traits::r_type_module_object_tag ){
>             T* obj = as_module_object<T>(x) ;
>             return *obj ;
>         }
> 
> so when the object returns from this as, a copy is involved. We return a
> T, not a T*, or a T&
> 
> We might be able to identify that we want a reference. that is more work.
> 
> It is worth making a few tests with some dummy classes that prints on
> copy constructor to see how many times it is used, etc ...


-- 
Darren Cook, Software Researcher/Developer

http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)


More information about the Rcpp-devel mailing list