Modify

Opened 5 years ago

Closed 5 years ago

#7330 closed Patches (fixed)

Patch adding move constructors and move assignments

Reported by: Antony Polukhin Owned by: Douglas Gregor
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 (2)

function_template.hpp.diff (2.1 KB) - added by Antony Polukhin 5 years ago.
function_test.cpp.diff (2.3 KB) - added by Antony Polukhin 5 years ago.

Download all attachments as: .zip

Change History (4)

Changed 5 years ago by Antony Polukhin

Attachment: function_template.hpp.diff added

Changed 5 years ago by Antony Polukhin

Attachment: function_test.cpp.diff added

comment:1 Changed 5 years ago by Antony Polukhin

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

comment:2 Changed 5 years ago by Antony Polukhin

Resolution: fixed
Status: newclosed

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

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Douglas Gregor.
The resolution will be deleted.

Add Comment


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

 
Note: See TracTickets for help on using tickets.