新的和malloc之间的区别 [英] difference beetween new and malloc

查看:122
本文介绍了新的和malloc之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

new和malloc之间的区别。与malloc()相比,使用new有什么好处

difference between new and malloc. What is the advantage of using new as compared to malloc()

推荐答案

堆栈溢出答案


new将分配内存并调用构造函数物体。 (删除会调用析构函数并释放memomry)。

malloc只会分配内存。 (它只会释放内存)。
new will allocate the memory and call the constructor of the object. (delete will call the destructor and free the memomry).
malloc will only allocate the memory. (it will only free the memory).


new是一个更好的选择,你可以分配你的程序中有类型的内存

malloc()只分配内存或不具有类型

您可以从MSDN中看到
new is a better choice that is you can alloc the memory have the type in your program
The malloc() is only alloc the memory or not have the type
You can see from the MSDN


这篇关于新的和malloc之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆