Subject: [Boost-bugs] [Boost C++ Libraries] #7330: Patch adding move constructors and move assignments
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-09-05 18:29:57
#7330: Patch adding move constructors and move assignments
-------------------------------------+--------------------------------------
Reporter: apolukhin | Owner: dgregor
Type: Patches | Status: new
Milestone: To Be Determined | Component: function
Version: Boost Development Trunk | Severity: Optimization
Keywords: |
-------------------------------------+--------------------------------------
Use of move constructor and move assignment reduce memory
allocation/deallocations count and do not call functor copy operator for
big functors.
Example:
{{{
struct big_aggregating_structure {
int disable_small_objects_optimizations[32];
void operator()() {}
};
...
function<void()> f1 = big_aggregating_structure();
function<void()> f2 = f1; // will call new, copy()
function<void()> f3 = std::move(f1); // Just swaps pointers, leaves f1
empty
f3 = f2; // Will call new, copy(), destory(), delete
f3 = std::move(f2); // Just swaps pointers, leaves f2 empty (calls
destory(), delete for f3)
{
function<void()> f_new1 = big_aggregating_structure();
function<void()> f_new2 = std::move(f_new1);
// Without move constructor, there will be additional new, copy(),
destroy(), delete calls
}
}}}
This patch could be very usefull for boost::asio, boost::thread and
anyone, who uses boost::function in STL containers on C++11 compilers.
Patch was tested on MSVC2010, GCC-4.6
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/7330> 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:50:10 UTC