<tfoot id='LgPyh'></tfoot>

<small id='LgPyh'></small><noframes id='LgPyh'>

      • <bdo id='LgPyh'></bdo><ul id='LgPyh'></ul>

      1. <legend id='LgPyh'><style id='LgPyh'><dir id='LgPyh'><q id='LgPyh'></q></dir></style></legend>
      2. <i id='LgPyh'><tr id='LgPyh'><dt id='LgPyh'><q id='LgPyh'><span id='LgPyh'><b id='LgPyh'><form id='LgPyh'><ins id='LgPyh'></ins><ul id='LgPyh'></ul><sub id='LgPyh'></sub></form><legend id='LgPyh'></legend><bdo id='LgPyh'><pre id='LgPyh'><center id='LgPyh'></center></pre></bdo></b><th id='LgPyh'></th></span></q></dt></tr></i><div id='LgPyh'><tfoot id='LgPyh'></tfoot><dl id='LgPyh'><fieldset id='LgPyh'></fieldset></dl></div>

        std::vector 与 std::list 与 std::slist 的相对性能?

        时间:2023-06-04
        <i id='AeQnC'><tr id='AeQnC'><dt id='AeQnC'><q id='AeQnC'><span id='AeQnC'><b id='AeQnC'><form id='AeQnC'><ins id='AeQnC'></ins><ul id='AeQnC'></ul><sub id='AeQnC'></sub></form><legend id='AeQnC'></legend><bdo id='AeQnC'><pre id='AeQnC'><center id='AeQnC'></center></pre></bdo></b><th id='AeQnC'></th></span></q></dt></tr></i><div id='AeQnC'><tfoot id='AeQnC'></tfoot><dl id='AeQnC'><fieldset id='AeQnC'></fieldset></dl></div>
        <tfoot id='AeQnC'></tfoot>

      3. <small id='AeQnC'></small><noframes id='AeQnC'>

            • <bdo id='AeQnC'></bdo><ul id='AeQnC'></ul>
                <legend id='AeQnC'><style id='AeQnC'><dir id='AeQnC'><q id='AeQnC'></q></dir></style></legend>
                  <tbody id='AeQnC'></tbody>

                • 本文介绍了std::vector 与 std::list 与 std::slist 的相对性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  对于不需要随机访问列表元素的简单链表,使用 std::list 代替 std 是否有任何显着优势(性能或其他)::vector?如果需要向后遍历,在遍历列表元素之前使用 std::slistreverse() 会更有效吗?

                  For a simple linked list in which random access to list elements is not a requirement, are there any significant advantages (performance or otherwise) to using std::list instead of std::vector? If backwards traversal is required, would it be more efficient to use std::slist and reverse() the list prior to iterating over its elements?

                  推荐答案

                  像往常一样,性能问题的最佳答案是 profile 适用于您的用例的两种实现,看看哪个更快.

                  As usual the best answer to performance questions is to profile both implementations for your use case and see which is faster.

                  一般来说,如果你有插入数据结构(不是在最后)那么 vector 可能会更慢,否则在大多数情况下 vector 预计会执行如果仅针对 数据局部性问题,则比 list 更好,这意味着如果数据集中相邻的两个元素在内存中相邻,那么下一个元素将已经在处理器的缓存中,并且不必将内存页错误到缓存中.

                  In general if you have insertions into the data-structure (other than at the end) then vector may be slower, otherwise in most cases vector is expected to perform better than list if only for data locality issues, this means that if two elements that are adjacent in the data-set are adjacent in memory then the next element will already be in the processor's cache and will not have to page fault the memory into the cache.

                  还要记住,vector 的空间开销是恒定的(3 个指针),而 list 的空间开销是为每个元素支付的,这也减少了任意时刻可以驻留在缓存中的完整元素(数据加上开销)的数量.

                  Also keep in mind that the space overhead for a vector is constant (3 pointers) while the space overhead for a list is paid for each element, this also reduces the number of full elements (data plus overhead) that can reside in the cache at any one time.

                  这篇关于std::vector 与 std::list 与 std::slist 的相对性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:尝试实现 下一篇:如何存储非常大的数字?

                  相关文章

                    <bdo id='X2sui'></bdo><ul id='X2sui'></ul>
                  <i id='X2sui'><tr id='X2sui'><dt id='X2sui'><q id='X2sui'><span id='X2sui'><b id='X2sui'><form id='X2sui'><ins id='X2sui'></ins><ul id='X2sui'></ul><sub id='X2sui'></sub></form><legend id='X2sui'></legend><bdo id='X2sui'><pre id='X2sui'><center id='X2sui'></center></pre></bdo></b><th id='X2sui'></th></span></q></dt></tr></i><div id='X2sui'><tfoot id='X2sui'></tfoot><dl id='X2sui'><fieldset id='X2sui'></fieldset></dl></div>
                  <legend id='X2sui'><style id='X2sui'><dir id='X2sui'><q id='X2sui'></q></dir></style></legend>
                  <tfoot id='X2sui'></tfoot>

                  <small id='X2sui'></small><noframes id='X2sui'>