Explain the Small String Optimization (SSO) used by many STL implementations.
Last updated
Small String Optimization stores short strings (often up to ~15 chars on 64-bit) in an inline buffer inside the
std::stringobject, switching to heap allocation only when the content exceeds that threshold.It avoids heap allocations for common short strings and improves cache locality.
Costs: larger
sizeof(std::string)(typically 24-32 bytes), implementation-defined thresholds, and moves of short strings copy the buffer rather than stealing a pointer.