|
Boost Users : |
Subject: [Boost-users] [GIL] Performance warning...
From: Eloi Du Bois (eloi.du.bois_at_[hidden])
Date: 2009-11-27 10:06:41
Hi all,
I am creating a bunch of function for channel merging, thus I was looking in
channel_algorithm.hpp and I saw something that may slow down processes...
I don't know if I'm right, but on line 362:
/// \ingroup ChannelConvertAlgorithm
> /// \brief Converting from one channel type to another.
> template <typename DstChannel, typename SrcChannel> // Model ChannelConcept
> (could be channel references)
> inline typename channel_traits<DstChannel>::value_type channel_convert(*SrcChannel
> src*) {
> return channel_converter<typename
> channel_traits<SrcChannel>::value_type,
> typename
> channel_traits<DstChannel>::value_type>()(src);
> }
>
There is no reference on parameter ***src*.*
*That* *not* *a very good idea because references aren't hold by templates
function (even if inlined). This may invoke copy constructor and can slow
down the processes a "lot"...
Here is an example that shows I'm right in theory:
// "Slow" on big objects
> template<typename P>
> inline void testPtr1(P a) {
> std::cout << "In called function inequality ptr of a: " << (int)&a <<
> std::endl;
> }
>
> // Better
> template<typename P>
> inline void testPtr2(P &a) {
> std::cout << "In called function equality ptr of a: " << (int)&a <<
> std::endl;
> }
>
> template<typename P>
> void test(const P & a) {
> std::cout << "Base ptr of a: " << (int)&a << std::endl;
> testPtr1(a);
> }
>
> int main() {
> int a = 0;
> test(a);
> return 0;
> }
>
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net