Is std::string ref-counted in GCC 4.x / C++11?(在 GCC 4.x/C++11 中是否计算了 std::string 引用?)
问题描述
当使用带有 -std=c++0x 或 -std=c++11 的 gcc 4 时 std::string 引用计数代码>?
Is std::string reference-counted when using gcc 4 with -std=c++0x or -std=c++11?
推荐答案
看libstdc++ 文档 我发现(有关更多信息,请参阅链接):
Looking at libstdc++ documentation I find (see the link for more info):
一个字符串看起来像这样:
A string looks like this:
[_Rep]
_M_length
[basic_string<char>] _M_capacity
_M_dataplus _M_refcount
_M_p ----------------> unnamed array of char_type
所以,是的,它是参考计数的.另外,来自这里的讨论:
So, yes it is ref counted. Also, from the discussion here:
是的,std::string 在某些时候会变成非引用计数,但是作为非引用计数的字符串在 C++98 中也是有效的,一个选项是切换到非引用计数的字符串-std=c++98 和 -std=c++11 模式.我不是说这就是会发生的事情,但它可能会发生.
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.
所以,似乎有计划将其更改为符合标准(但我不知道进展如何).
So, it seems there are plans to change it to be conforming (I don't know how the progress is going though).
更新正如 emsr 在评论中指出的那样,目前有一个非引用计数扩展名为 vstring.h,这似乎是它没有取代 std::string 的唯一原因> 是因为 ABI 兼容性.此处有一个 SO 问题.
Update
As emsr points out in the comments, there is currently a non-reference counted extension called vstring.h, and it seems the only reason it hasn't replaced std::string is because of ABI compatibility. There is an SO question about it here.
这篇关于在 GCC 4.x/C++11 中是否计算了 std::string 引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 GCC 4.x/C++11 中是否计算了 std::string 引用?
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- CString 到 char* 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
