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

  • <small id='2N1Um'></small><noframes id='2N1Um'>

    1. <tfoot id='2N1Um'></tfoot>

      <legend id='2N1Um'><style id='2N1Um'><dir id='2N1Um'><q id='2N1Um'></q></dir></style></legend>
      1. C++ std::vector 是如何实现的?

        How is C++ std::vector implemented?(C++ std::vector 是如何实现的?)

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

          <legend id='qgKR2'><style id='qgKR2'><dir id='qgKR2'><q id='qgKR2'></q></dir></style></legend>

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

          • <bdo id='qgKR2'></bdo><ul id='qgKR2'></ul>
            <tfoot id='qgKR2'></tfoot>

                1. 本文介绍了C++ std::vector 是如何实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在使用 std::vector,最近我问自己这个问题:std::vector 是如何实现的?"

                  I have been using std::vector a lot, and recently I asked myself this question: "How is std::vector implemented?"

                  我有两个选择:

                  1) 链表,然后让 API 感觉像是随机访问(即重载 operator[]).

                  1) Linked list, and then making the API feel like random access (i.e. overloading operator[]).

                  2) 使用 new,例如Foo* temp = new Foo[20]:我相信他们会做这样的事情,但随后又提出了一个问题.他们是否总是分配最大 (uint32_t) 存储空间来提供随机访问?(这在内存方面是低效的.)

                  2) Using new, e.g. Foo* temp = new Foo[20]: I believe they do something like this, but then it raises one more question. Do they always allocate a maximum (uint32_t) storage to give random access? (This is inefficient in terms of memory.)

                  或者还有什么我应该注意的吗?

                  Or is there something else that I should be aware of?

                  推荐答案

                  它是通过使用底层数组实现的.

                  It's implemented by using an underlying array.

                  不可能实现 std::vector 使用链表,因为标准保证列表中的元素将保存在连续内存中.

                  It's not possible to implement a std::vector<T> with a linked list because the standard guarantees the elements in the list will be held in contiguous memory.

                  这篇关于C++ std::vector 是如何实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is the past-the-end iterator in STL C++?(STL C++ 中的最后迭代器是什么?)
                  vector::at vs. vector::operator[](vector::at 与 vector::operator[])
                  C++ equivalent of StringBuffer/StringBuilder?(C++ 等效于 StringBuffer/StringBuilder?)
                  Adding types to the std namespace(将类型添加到 std 命名空间)
                  Is the C++ std::set thread-safe?(C++ std::set 线程安全吗?)
                  How to use std::find/std::find_if with a vector of custom class objects?(如何将 std::find/std::find_if 与自定义类对象的向量一起使用?)

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

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