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

      <bdo id='34u0C'></bdo><ul id='34u0C'></ul>
    <tfoot id='34u0C'></tfoot>
    <legend id='34u0C'><style id='34u0C'><dir id='34u0C'><q id='34u0C'></q></dir></style></legend>

      1. <small id='34u0C'></small><noframes id='34u0C'>

      2. "new" 和有什么不一样?和“malloc"和“calloc"在 C++ 中?

        What is the difference between quot;newquot; and quot;mallocquot; and quot;callocquot; in C++?(new 和有什么不一样?和“malloc和“calloc在 C++ 中?)
          <tbody id='FvWCq'></tbody>
          <bdo id='FvWCq'></bdo><ul id='FvWCq'></ul>
          <tfoot id='FvWCq'></tfoot>
          1. <i id='FvWCq'><tr id='FvWCq'><dt id='FvWCq'><q id='FvWCq'><span id='FvWCq'><b id='FvWCq'><form id='FvWCq'><ins id='FvWCq'></ins><ul id='FvWCq'></ul><sub id='FvWCq'></sub></form><legend id='FvWCq'></legend><bdo id='FvWCq'><pre id='FvWCq'><center id='FvWCq'></center></pre></bdo></b><th id='FvWCq'></th></span></q></dt></tr></i><div id='FvWCq'><tfoot id='FvWCq'></tfoot><dl id='FvWCq'><fieldset id='FvWCq'></fieldset></dl></div>
          2. <legend id='FvWCq'><style id='FvWCq'><dir id='FvWCq'><q id='FvWCq'></q></dir></style></legend>

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

                  本文介绍了"new" 和有什么不一样?和“malloc"和“calloc"在 C++ 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  new"和new"有什么区别?和malloc"和calloc";和其他家庭成员?

                  What is the difference between "new" and "malloc" and "calloc" and others in family?

                  (何时)除了new"之外我还需要什么吗??

                  (When) Do I need anything other than "new" ?

                  其中一个是否使用其他实现?

                  Is one of them implemented using any other?

                  推荐答案

                  newdelete 是 C++ 特定的功能.它们在 C 中不存在. malloc 是老派的 C 做事方式.大多数情况下,您不需要在 C++ 中使用它.

                  new and delete are C++ specific features. They didn't exist in C. malloc is the old school C way to do things. Most of the time, you won't need to use it in C++.

                  • malloc 分配未初始化的内存.分配的内存必须用 free 释放.
                  • callocmalloc 类似,但使用常量 (0) 初始化分配的内存.需要用 free 释放.
                  • new 通过调用构造函数(如果它是一个对象)来初始化分配的内存.用 new 分配的内存应该用 delete 释放(它依次调用析构函数).它不需要您手动指定所需的大小并将其转换为适当的类型.因此,它更现代,更不容易出错.
                  • malloc allocates uninitialized memory. The allocated memory has to be released with free.
                  • calloc is like malloc but initializes the allocated memory with a constant (0). It needs to be freed with free.
                  • new initializes the allocated memory by calling the constructor (if it's an object). Memory allocated with new should be released with delete (which in turn calls the destructor). It does not need you to manually specify the size you need and cast it to the appropriate type. Thus, it's more modern and less prone to errors.

                  这篇关于"new" 和有什么不一样?和“malloc"和“calloc"在 C++ 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                  Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                  How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                  What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                  Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                  How boost auto-linking makes choice?(boost自动链接如何做出选择?)

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

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

                  2. <small id='lAgQt'></small><noframes id='lAgQt'>

                        <tbody id='lAgQt'></tbody>

                        • <tfoot id='lAgQt'></tfoot>

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