Trivial Relocation Through Time

By Mungo Gill

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.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.