[Rcpp-devel] Rcpp 0.10.0

Romain Francois romain at r-enthusiasts.com
Thu Nov 15 01:06:26 CET 2012


Le 15/11/12 01:02, Darren Cook a écrit :
>> 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

Good point. Feel free to get started ;-)

> 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 ...
>
>


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30

R Graph Gallery: http://gallery.r-enthusiasts.com
`- http://bit.ly/SweN1Z : SuperStorm Sandy

blog:            http://romainfrancois.blog.free.fr
|- http://bit.ly/RE6sYH : OOP with Rcpp modules
`- http://bit.ly/Thw7IK : Rcpp modules more flexible



More information about the Rcpp-devel mailing list