From Jason Turner
Watch on YouTube

Summary

Jason explores C++23's new basic_string::resize_and_overwrite function, which improves performance when initializing strings that will be immediately overwritten with new content. Using Compiler Explorer to analyze the generated assembly, he demonstrates how the traditional approach of first resizing a string and then filling it results in unnecessary initialization via memset. The new feature eliminates this wasteful step by allowing a single operation that both sizes the buffer and populates it with content through a callback function.

Resources

Tags