Re: [Boost-bugs] [Boost C++ Libraries] #1910: function::swap should avoid doing memory allocations

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #1910: function::swap should avoid doing memory allocations
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-09-05 23:23:59


#1910: function::swap should avoid doing memory allocations
---------------------------+------------------------------------------------
  Reporter: niels_dekker | Owner: dgregor
      Type: Bugs | Status: closed
 Milestone: Boost 1.36.0 | Component: function
   Version: Boost 1.35.0 | Severity: Problem
Resolution: fixed | Keywords:
---------------------------+------------------------------------------------

Comment(by niels_dekker):

 Replying to [comment:3 dgregor]:
> (In [48615]) Improve the performance of Boost.Function's swap.

 Sorry, I'm not yet entirely sure about your fix of
 [http://svn.boost.org/trac/boost/changeset/48615/trunk/boost/function/function_base.hpp
 function_base.hpp], as it says in ''manage_small'':
 {{{
   if (op == move_functor_tag) {
      reinterpret_cast<functor_type*>(&in_buffer.data)->~Functor();
   }
 }}}

 As a consequence, it seems to me that the functor may be destructed too
 many times. The following BOOST_CHECK fails on my computer:

 {{{
     static unsigned construction_count;
     static unsigned destruction_count;

     struct MyFunctor {
         MyFunctor() { ++construction_count; }
         MyFunctor(const MyFunctor &) { ++construction_count; }
         ~MyFunctor() { ++destruction_count; }
         int operator()() { return 0; }
     };


 int test_main(int, char* [])
 {
     {
       boost::function0<int> f;
       boost::function0<int> g;
       f = MyFunctor();
       g = MyFunctor();
       f.swap(g);
     }
     // MyFunctor objects should be constructed at least
     // as many times as they are destructed.
     BOOST_CHECK(construction_count >= destruction_count);
 }

 }}}

-- 
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1910#comment:5>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:58 UTC