Modify

Ticket #7330 (closed Patches: fixed)

Opened 20 months ago

Last modified 19 months ago

Patch adding move constructors and move assignments

Reported by: apolukhin Owned by: dgregor
Milestone: To Be Determined Component: function
Version: Boost Development Trunk Severity: Optimization
Keywords: Cc:

Description

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

Attachments

function_template.hpp.diff Download (2.1 KB) - added by apolukhin 20 months ago.
function_test.cpp.diff Download (2.3 KB) - added by apolukhin 20 months ago.

Change History

Changed 20 months ago by apolukhin

Changed 20 months ago by apolukhin

comment:1 Changed 19 months ago by apolukhin

(In [80552]) Add move assignment and move constructors to Boost.Function (refs #7330)

comment:2 Changed 19 months ago by apolukhin

  • Status changed from new to closed
  • Resolution set to fixed

(In [80738]) Merge from trunk: added move assignment and move constructors to Boost.Function (fixes #7330)

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.