1. <small id='qBueh'></small><noframes id='qBueh'>

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

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

      放置新建和删除

      placement new and delete(放置新建和删除)
        <tbody id='qmHiJ'></tbody>

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

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

              • <tfoot id='qmHiJ'></tfoot>
              • <i id='qmHiJ'><tr id='qmHiJ'><dt id='qmHiJ'><q id='qmHiJ'><span id='qmHiJ'><b id='qmHiJ'><form id='qmHiJ'><ins id='qmHiJ'></ins><ul id='qmHiJ'></ul><sub id='qmHiJ'></sub></form><legend id='qmHiJ'></legend><bdo id='qmHiJ'><pre id='qmHiJ'><center id='qmHiJ'></center></pre></bdo></b><th id='qmHiJ'></th></span></q></dt></tr></i><div id='qmHiJ'><tfoot id='qmHiJ'></tfoot><dl id='qmHiJ'><fieldset id='qmHiJ'></fieldset></dl></div>
                <legend id='qmHiJ'><style id='qmHiJ'><dir id='qmHiJ'><q id='qmHiJ'></q></dir></style></legend>
                本文介绍了放置新建和删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                删除这里分配的所有内存的正确方法是什么?

                What is the right method to delete all the memory allocated here?

                  const char* charString = "Hello, World";
                  void *mem = ::operator new(sizeof(Buffer) + strlen(charString) + 1);
                  Buffer* buf = new(mem) Buffer(strlen(charString));
                
                  delete (char*)buf;
                

                  const char* charString = "Hello, World";
                  void *mem = ::operator new(sizeof(Buffer) + strlen(charString) + 1);
                  Buffer* buf = new(mem) Buffer(strlen(charString));
                
                  delete buf;
                

                还是两者都一样?

                推荐答案

                正确的方法是:

                buf->~Buffer();
                ::operator delete(mem);
                

                您只能使用 delete operator 删除您从 new operator 收到的内容.如果直接调用operator new函数,也必须直接调用operator delete函数,并且必须手动调用析构函数.

                You can only delete with the delete operator what you received from the new operator. If you directly call the operator new function, you must also directly call the operator delete function, and must manually call the destructor as well.

                这篇关于放置新建和删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Consistent pseudo-random numbers across platforms(跨平台一致的伪随机数)
                Vary range of uniform_int_distribution(改变uniform_int_distribution的范围)
                What is a seed in terms of generating a random number?(就生成随机数而言,种子是什么?)
                Is 1.0 a valid output from std::generate_canonical?(1.0 是 std::generate_canonical 的有效输出吗?)
                Getting big random numbers in C/C++(在 C/C++ 中获取大随机数)
                What is the best way to generate random numbers in C++?(在 C++ 中生成随机数的最佳方法是什么?)

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

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

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