来自 the manual:
In the GCC 5.1 release libstdc++ introduced a new library ABI that includes new implementations of std::string and std::list. These changes were necessary to conform to the 2011 C++ standard which forbids Copy-On-Write strings and requires lists to keep track of their size.
可以使用 _GLIBCXX_USE_CXX11_ABI 宏来控制库 header 是使用旧 ABI 还是新 ABI,而与正在使用的“-std”无关。
我想知道使用此“兼容性 ABI”的含义是什么?我猜想小字符串操作的运行时性能会受到影响(我假设是负面的),并且列表大小访问从 O(1) (C11 ABI) 到 O(N)(兼容性 ABI)。
- 我的猜测是否正确,有人可以详细说明吗?
- 是否还有其他我遗漏的含义?原子和并发特性呢?有什么影响吗?
最佳答案
您的第一个问题实际上已由手册本身回答:
... the choice of ABI to use is independent of the -std option used to compile your code... This ensures that the -std does not change the ABI, so that it is straightforward to link C++03 and C++11 code together.
关于第二个问题,恐怕很难概括影响,因为它取决于您的代码如何使用标准库。它会复制很多字符串吗?多久查询一次列表大小?代码是多线程的吗?
虽然原子和并发是在 C++11 的标准中引入的,但我猜想 stdlib++ 写时复制机制无论如何已经使用了它的变体。这些实现通常是线程安全的。
也许您没有直接提及的一件事是对依赖于这些行为的其他标准组件的影响,例如 list::splice
关于c++ - 使用 _GLIBCXX_CXX11_ABI 来使用具有 C++ 11/14 功能的 pre-5.1 C++ ABI 有什么影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34351207/