Inside STL: The string -- Raymond Chen
You might think that a std::string (and all of its friends in the std::basic_string family) are basically a vector of characters internally. But strings are organized differently due to specific optimizations permitted for strings but not for vectors.
Inside STL: The string
By Raymond Chen
From the article:
The starting point for a
std::is this:¹basic_string template<typename T> struct basic_string { T* ptr; size_t size; size_t capacity; };The
ptris a pointer to the beginning of the string contents.The
sizeis the number of characters in the string, not including the null terminator.The
capacityis the string capacity, not including the null terminator.The picture for this simplified version is as follows:


Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
egistration is now open for CppCon 2023! The conference starts on October 1 and will be held 
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held
Registration is now open for CppCon 2023! The conference starts on October 1 and will be held