1. <tfoot id='y4sUT'></tfoot>
    <legend id='y4sUT'><style id='y4sUT'><dir id='y4sUT'><q id='y4sUT'></q></dir></style></legend>

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

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

    1. 基于堆栈缓冲区的 STL 分配器?

      Stack-buffer based STL allocator?(基于堆栈缓冲区的 STL 分配器?)
        <bdo id='wFeRL'></bdo><ul id='wFeRL'></ul>

                  <tbody id='wFeRL'></tbody>

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

                <tfoot id='wFeRL'></tfoot>

                <legend id='wFeRL'><style id='wFeRL'><dir id='wFeRL'><q id='wFeRL'></q></dir></style></legend>
              • <i id='wFeRL'><tr id='wFeRL'><dt id='wFeRL'><q id='wFeRL'><span id='wFeRL'><b id='wFeRL'><form id='wFeRL'><ins id='wFeRL'></ins><ul id='wFeRL'></ul><sub id='wFeRL'></sub></form><legend id='wFeRL'></legend><bdo id='wFeRL'><pre id='wFeRL'><center id='wFeRL'></center></pre></bdo></b><th id='wFeRL'></th></span></q></dt></tr></i><div id='wFeRL'><tfoot id='wFeRL'></tfoot><dl id='wFeRL'><fieldset id='wFeRL'></fieldset></dl></div>
                本文介绍了基于堆栈缓冲区的 STL 分配器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!


                我想知道有一个符合 C++ 标准库的 allocator 是否可行,它使用位于堆栈中的(固定大小的)缓冲区.

                I was wondering if it practicable to have an C++ standard library compliant allocator that uses a (fixed sized) buffer that lives on the stack.

                不知何故,这个问题似乎还没有在 SO 上被这样问过,尽管它可能已经在别处隐含地回答了.

                Somehow, it seems this question has not been ask this way yet on SO, although it may have been implicitly answered elsewhere.


                So basically, it seems, as far as my searches go, that it should be possible to create an allocator that uses a fixed size buffer. Now, on first glance, this should mean that it should also be possible to have an allocator that uses a fixed size buffer that "lives" on the stack, but it does appear, that there is no widespread such implementation around.


                Let me give an example of what I mean:

                { ...
                  char buf[512];
                  typedef ...hmm?... local_allocator; // should use buf
                  typedef std::basic_string<char, std::char_traits<char>, local_allocator> lstring;
                  lstring str; // string object of max. 512 char


                另一个问题的答案(感谢 R. Martinho Fernandes) 链接到来自 Chromium 源的基于堆栈的分配器:http://src.chromium.org/viewvc/chrome/trunk/src/base/stack_container.h

                The answer to this other question (thanks to R. Martinho Fernandes) links to a stack based allocator from the chromium sources: http://src.chromium.org/viewvc/chrome/trunk/src/base/stack_container.h

                然而,这个类看起来非常奇特,特别是因为这个 StackAllocator 没有默认的构造函数——我在想每个分配器类都需要一个默认的ctor.

                However, this class seems extremely peculiar, especially since this StackAllocator does not have a default ctor -- and there I was thinking that every allocator class needs a default ctor.


                显然,是一个符合标准的堆栈分配器 来自一个 Howard Hinnant.

                它通过使用固定大小的缓冲区(通过引用的arena 对象)并在请求太多空间时回退到堆来工作.

                It works by using a fixed size buffer (via a referenced arena object) and falling back to the heap if too much space is requested.


                This allocator doesn't have a default ctor, and since Howard says:

                我已经用一个完全符合 C++11 的新分配器更新了这篇文章.

                I've updated this article with a new allocator that is fully C++11 conforming.


                I'd say that it is not a requirement for an allocator to have a default ctor.

                这篇关于基于堆栈缓冲区的 STL 分配器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



                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 与自定义类对象的向量一起使用?)
                <tfoot id='Xf7ng'></tfoot>
                  <tbody id='Xf7ng'></tbody>

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

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

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