当使用带有 -std=c++0x
或 -std=c++11的 gcc 4 时,
?std::string
是否被引用计数
最佳答案
看libstdc++ documentation我发现(查看链接了解更多信息):
字符串如下所示:
[_Rep]
_M_length
[basic_string<char>] _M_capacity
_M_dataplus _M_refcount
_M_p ----------------> unnamed array of char_type
所以,是的,它是 ref 计数的。另外,来自讨论 here :
Yes, std::string will be made non-reference counting at some point, but as a non-reference-counted string is valid in C++98 as well, one option would be to switch to a non-ref-counted string for both -std=c++98 and -std=c++11 modes. I'm not saying that's what will happen, but it could be.
所以,似乎有计划将其更改为符合要求(但我不知道进展如何)。
更新
正如 emsr 在评论中指出的那样,目前有一个名为 vstring.h
的非引用计数扩展,这似乎是它没有替换 std::string
的唯一原因> 是因为 ABI 兼容性。有一个关于它的问题 here .
https://stackoverflow.com/questions/12520192/