简体   繁体   English

在现代 C++ 中,侵入式容器是否仍然比非侵入式容器具有性能优势?

[英]Do Intrusive containers still have performance advantages over non-intrusive ones in modern C++?

Boost.Intrusive容器是否仍然比现代 C++ 中的非侵入式标准( std:: )容器具有性能优势(具有移动语义、 emplace_back等)?

Yes, there are numerous advantages of intrusive containers that still remain even when move semantics are used with STL containers.是的,即使将移动语义与 STL 容器一起使用,侵入式容器仍有许多优点。 In particular, memory locality is still likely going to be better, which can yield great performance gains in certain scenarios.特别是,内存局部性可能会更好,这在某些情况下可以产生很大的性能提升。 Also, iterators can still benefit greatly, and avoiding any overhead from exceptions can speed up insertion/deletion operations.此外,迭代器仍然可以受益匪浅,避免任何来自异常的开销可以加快插入/删除操作。

Consider Table 19.1 from the Intrusive and non-intrusive containers section of the Boost reference.考虑来自 Boost 参考的侵入式和非侵入式容器部分的表 19.1。 Most of these advantages likely remain, such as:这些优势中的大部分可能仍然存在,例如:

  • Insertion/Erasure time插入/擦除时间
  • Memory locality内存位置
  • Exception guarantees异常保证
  • Computation of iterator from value从值计算迭代器
  • Memory use内存使用

The Boost documentation has detailed performance metrics which show the relative performance of a wide variety of operations in different scenarios. Boost 文档有详细的性能指标,显示了不同场景下各种操作的相对性能。 If you consider which of these is not affected primarily by allocation, there is still considerable potential.如果您考虑其中哪些主要不受分配的影响,则仍有相当大的潜力。

Of course, ultimately the question of performance and optimality is going to depend primarily on your particular application, so it is inadvisable to make generalised statements about the "best" or "fastest" approach.当然,最终性能和优化问题将主要取决于您的特定应用程序,因此不建议对“最佳”或“最快”方法进行概括性陈述。 There is no substitute for profiling your particular code and assessing the tradeoffs involved with the additional complexity.分析您的特定代码并评估额外复杂性所涉及的权衡是无可替代的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM