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

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

        • <bdo id='NhElw'></bdo><ul id='NhElw'></ul>
      1. <legend id='NhElw'><style id='NhElw'><dir id='NhElw'><q id='NhElw'></q></dir></style></legend>
        <tfoot id='NhElw'></tfoot>

      2. C++中向量的初始容量

        时间:2023-09-16

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

              <small id='1JVTP'></small><noframes id='1JVTP'>

              • <legend id='1JVTP'><style id='1JVTP'><dir id='1JVTP'><q id='1JVTP'></q></dir></style></legend>

                  <bdo id='1JVTP'></bdo><ul id='1JVTP'></ul>
                • 本文介绍了C++中向量的初始容量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  使用默认构造函数创建的 std::vectorcapacity() 是多少?我知道 size() 为零.我们可以声明默认构造的向量不会调用堆内存分配吗?

                  What is the capacity() of an std::vector which is created using the default constuctor? I know that the size() is zero. Can we state that a default constructed vector does not call heap memory allocation?

                  通过这种方式,可以使用单个分配创建具有任意保留的数组,例如 std::vector;四;iv.reserve(2345);.假设出于某种原因,我不想在 2345 上启动 size().

                  This way it would be possible to create an array with an arbitrary reserve using a single allocation, like std::vector<int> iv; iv.reserve(2345);. Let's say that for some reason, I do not want to start the size() on 2345.

                  例如,在 Linux(g++ 4.4.5,内核 2.6.32 amd64)上

                  For example, on Linux (g++ 4.4.5, kernel 2.6.32 amd64)

                  #include <iostream>
                  #include <vector>
                  
                  int main()
                  {
                    using namespace std;
                    cout << vector<int>().capacity() << "," << vector<int>(10).capacity() << endl;
                    return 0;
                  }
                  

                  打印0,10.这是规则,还是取决于 STL 供应商?

                  printed 0,10. Is it a rule, or is it STL vendor dependent?

                  推荐答案

                  该标准没有指定容器的初始 capacity 应该是多少,因此您依赖于实现.一个常见的实现将从零开始容量,但不能保证.另一方面,没有办法改善 std::vector 的策略.四;iv.reserve(2345); 所以坚持下去.

                  The standard doesn't specify what the initial capacity of a container should be, so you're relying on the implementation. A common implementation will start the capacity at zero, but there's no guarantee. On the other hand there's no way to better your strategy of std::vector<int> iv; iv.reserve(2345); so stick with it.

                  这篇关于C++中向量的初始容量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:多维向量 下一篇:Bjarne Stroustrup 说我们必须避免链表

                  相关文章

                  最新文章

                    <bdo id='N9cdz'></bdo><ul id='N9cdz'></ul>

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

                  <tfoot id='N9cdz'></tfoot>
                • <legend id='N9cdz'><style id='N9cdz'><dir id='N9cdz'><q id='N9cdz'></q></dir></style></legend>

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