关于自由存储区和堆的区别,网络上主要有两种观点:1.两者并不同,堆是new申请的空间,自由存储区是是malloc申请的空间。2.两者相同,用new和malloc申请的都叫堆(或者都叫自由存储区)。
到底该信哪一个?纠结!
还是查查MSDN吧,看看有没有收获。
打开MSDN,选择索引(Index),搜索new Operator,发现这么一句话:
The new operator is used to allocate objects and arrays of objects. The new operator allocates from a program memory area called the “free store.” In C, the free store is often referred to as the “heap.”
翻译过来就是:new 运算符用来分配对象和对象数组。new运算符从一个叫做“自由存储区”的程序内存区域分配内存。在C中,自由存储区也经常被称为“堆”。
不用我多说了,大家都明白了吧