C++11 std::shared_ptr's std::move() move semantic bottom analysis

The underlying analysis of std::move() movement semantics of std::shared_ptr

Before executing std::move():

Insert picture description here
Insert picture description here

After executing std::move():

Insert picture description here
Insert picture description here

Conclusion: a shallow copy

sizeof(std::shared_ptr) = 8 bytes
pss1: 0x0028fea8
pss2: 0x0028fea0
(the stack is inversely growing)
Observe the value of 8 bytes starting from pss1: 0x0028fea8 before std::move is
executed , and then after executing pss1: 0x0028fea8 After copying the value of the first 8 bytes to pss2: 0x0028fea0, clear the value of the first 8 bytes of pss1: 0x0028fea8.

process:

The function of std::move() is to convert an lvalue to an rvalue,
so when std::stdred_ptr<> pss2(std::move(pss1)) is executed, the move structure of std::shared_ptr<> is called Function (movement construction requires an rvalue), and the movement constructor is a shallow copy operation.

Guess you like

Origin blog.csdn.net/m0_37599645/article/details/112850845