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 引用?


基础教程推荐
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- C++结构和函数声明。为什么它不能编译? 2022-11-07