C++11 internal std::string representation (libstdc++)

一世执手 提交于 2019-12-05 04:26:25

GCC did move away from the refcounted string to follow the c++11 standard, but note that it is possible that your program will use it as part of the ABI compatibility implementation.

How it is refcounted

std::string doesn't have a _Rep_Base member but a pointer to _Rep with _Rep inheriting from _Rep_Base

It is what is explained here :

 *  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.

The buffer lies after the header...

Yes, but after the header of the _Rep object, and your string only has a pointer to it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!