Opened 10 years ago

Closed 10 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 10 years ago.
function_test.cpp.diff (2.3 KB ) - added by Antony Polukhin 10 years ago.

Download all attachments as: .zip

Change History (4)

by Antony Polukhin, 10 years ago

Attachment: function_template.hpp.diff added

by Antony Polukhin, 10 years ago

Attachment: function_test.cpp.diff added

comment:1 by Antony Polukhin, 10 years ago

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

comment:2 by Antony Polukhin, 10 years ago

Resolution: fixed
Status: newclosed

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

Note: See TracTickets for help on using tickets.