Lecture: Trivial Relocation Through Time

This talk considers why support for trivial relocatability would be a valuable addition to the C++ standard. Along the way, we also compare the various proposals that have been submitted to WG21 over the last eight years to achieve this.

A known performance issue for containers holding non-trivial types, such as std::vector<MyClass>, has been the focus of ongoing discussion for almost a decade. When such a container needs to increase its capacity, the MyClass objects need to be moved to a new location in memory. For simple types that are trivially copyable, that relocation can be performed quickly and efficiently by simply copying bytes and deallocating the original storage. For more complex types that are not trivially copyable, the container needs to loop over each existing object, moving each into the new location and destroying the old one. Numerous other types (such as std::string, std::unique_ptr, and std::list in some implementations), though not trivially copyable, could be relocated appropriately and efficiently with a simple memmove if such relocation were legal.


In this talk, we will first look at the efficiency aspects of relocation in more detail. We will then briefly compare and contrast the various — and thus far — unsuccessful attempts to introduce something akin to trivial relocatability into the standard, including:



  • N4034, “Destructive Move,” from Pablo Halpern in 2014

  • P0023, “Relocator: Efficiently moving objects,” from Denis Bider in 2016

  • P1029, “SG14 [[move_relocates]],” from Niall Douglas in 2018

  • P1144, “Object relocation in terms of move plus destroy,” from Arthur O'Dwyer in 2018


Library implementers have attempted to provide such a facility themselves, and we will contrast some of these approaches, including Facebook's open source Folly library and Bloomberg's open source BDE library.

Info

Day: 2023-04-21
Start time: 14:00
Duration: 01:30
Room: Bristol III

Links:

Feedback

Click here to let us know how you liked this event.

Concurrent Events