3 ms·
In any case, heap allocated string buffers like std::string are extremely inefficient as a default data type for short runs of text. Most text for example doesn
by jstimpfle 2y ago
In any case, heap allocated string buffers like std::string are extremely inefficient as a default data type for short runs of text. Most text for example doesn't need dynamic resizing once it's constructed, so here you can easily save 8 bytes for the "capacity" field. More bytes can be saved by acknowledging that in some situations, zero-terminated for short text runs may not actually be that bad, at least you can save the "size" field. That's another 4 to 8 bytes, probably 8 bytes due to alignment on 64-bit machines.
So no need to worry so much about 15 or 16 bytes SSO, or the empty string case (which as the other commenter points out you can easily model with a statically allocated "").