gpt4 book ai didi

c++ - GCC 的 "vstring"是什么?

转载 作者:IT老高 更新时间:2023-10-28 21:41:59 26 4
gpt4 key购买 nike

我阅读了一些 GCC 错误报告,那里的人在谈论“vstring”。上网搜索发现http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.2/vstring_8h.html .

有人可以详细说明它的用途和用途吗?为什么要使用它而不是 std::string?

最佳答案

GCC 的 vstring是一个通用的字符串类,在 GCC 4.1 的 libstdc++ 中引入实现。

兼容std::basic_string ,以及这些额外的细节:

  • 提供了两个基类:
    • 默认的避免引用计数,并针对短字符串进行了优化;
    • 替代方案仍然使用它(即引用​​计数),同时在一些低级领域(例如对齐)进行了改进。见 vstring_fwd.h一些有用的 typedef。
  • 重写了各种算法(例如替换),简化了代码并添加了简单的优化。
  • DR 431 的选项 3 适用于两个可用的基础,从而改进了对有状态分配器的支持。

DR431 是 Library Working Group Defect Report 431 ,选项 3 看起来像是为类实现更好的分配器支持,以允许更好的交换和其他与分配器相关的操作。

基本细节来自GCC 4.1's release notes ,在运行时库部分下。

编辑:

看起来这个扩展的最初目的是为 C++11 std::string 提供基础。执行。 Paolo Carlini,GCC/libstdc++ 贡献者,在此 GCC Bug Report 中发表评论那<ext/vstring.h>包含下一个 std::string 的非引用计数实验版本. 2012 年 4 月 12 日的评论:

What we tried to explain is that this sort of issue is well known and, more or less, affects any reference counted implementation... That is not the case when reference counting is not used and indeed it will not be used (per the new C++11 Standard) in a new implementation of std::string which we are currently showcasing as <ext/vstring.h>...

关于c++ - GCC 的 "vstring"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10463851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com