在GCC 4.x / C ++ 11中是否对std :: string进行了计数? [英] Is std::string ref-counted in GCC 4.x / C++11?

查看:43
本文介绍了在GCC 4.x / C ++ 11中是否对std :: string进行了计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将gcc 4与 -std = c ++ 0x 一起使用时, std :: string 是引用计数的吗? -std = c ++ 11

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):

字符串如下:

                       [_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兼容性。在此处

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进行了计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆