C++11 internal std::string representation (libstdc++)
问题 How std::string is internally represented in c++11 (libstdc++)? While digging inside the implementation, I found: /* A string looks like this: * * [_Rep] * _M_length * [basic_string<char_type>] _M_capacity * _M_dataplus _M_refcount * _M_p ----------------> unnamed array of char_type * * Where the _M_p points to the first character in the string, and * you cast it to a pointer-to-_Rep and subtract 1 to get a * pointer to the header. * * This approach has the enormous advantage that a string