User Tools

Site Tools


notes:stl_allocation_example

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
notes:stl_allocation_example [2013/02/25 17:01]
andy
notes:stl_allocation_example [2013/02/25 17:06]
andy [Typical Output]
Line 226: Line 226:
  
 ==== Typical Output ==== ==== Typical Output ====
 +
 +In contrast with the [[#​std::​list]] example above, ''​std::​map''​ invokes a substantial number of copy operations in the process of adding an element via assignment, as is done above.
 +
 +First, an in-place instance is constructed on the stack in response to the expression ''​MyClass(11)''​ as was done for ''​std::​list''​. Next, the default constructor is called to instantiate the instance in the map on the left-hand side of the assignment, and [[wikipedia>​placement new]] is used to copy this into the map --- I'm currently not sure why there appears to be yet another additional temporary value used in the process. At this point the destructors of both temporary instances are invoked. Then the assignment operator is used to overwrite the value in the map with the in-place instance created earlier. Finally, the destructor for the in-place instance is called, as with ''​std::​list''​.
  
 <​file>​ <​file>​
notes/stl_allocation_example.txt ยท Last modified: 2013/02/25 17:31 by andy