4 ms·
One of the more interesting optimizations I've seen is the C++ string class. A class instance takes up 24 bytes, many of which weren't used, so for short strin
by dekhn 7y ago
One of the more interesting optimizations I've seen is the C++ string class. A class instance takes up 24 bytes, many of which weren't used, so for short strings the data was stored inline rather than having a pointer to external memory. This is big if you have an app that has millions of tiny strings.
- chrchang523 7y agoNote that std::string data representation, and the associated set of small-string optimizations, are highly implementation-dependent; it even differs significantly between clang and gcc's standard libraries. For gcc, std::string size has been 32 bytes on 64-bit targets for the last several years.
- dekhn 7y agoYep. You can see some more context here: http://scottmeyers.blogspot.com/2012/04/stdstring-sso-and-move-semantics.html http://scottmeyers.blogspot.com/2012/04/stdstring-sso-and-mo... I don't know if there are any canonical writeups on the various string implementations and their performance implications wrt modern hardware.