c++ - GCC 4.x/C++11 中的 std::string 引用计数了吗?

当使用带有 -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/

相关文章:

c++ - 析构函数可以是最终的吗?

c++ - C++ 标准是否对 float 的表示做了任何规定?

c++ - 编译lua代码,存储字节码然后加载并执行

c++ - 库已链接,但引用未定义

c++ - 如何在 Windows 上找到 Qt5 CMake 模块

c++ - 从基类构造函数调用纯虚函数

c++ - 与 win32 CRITICAL_SECTION 相比的 std::mutex 性能

c++ - 如何使用 C++ 模板减少编译时间

c++ - 什么是 C++ 内联类?

c++ - 三元表达式中的逗号混淆