c++ - C++ 编译器一般是 "optimize"malloc 和 free to new and delete 吗?

标签 c++ c malloc compiler-optimization free

如果我正在编写 100% ANSI C 但在 .cpp 文件中编译,编译器会自动“优化”malloc 并免费调用 new 和 delete 吗?考虑到他们的差异,这甚至有意义吗?我不认为这是它的工作原理,但我的一个 friend 说这是发生了什么。

最佳答案

C++ 在 c.malloc 中非常具体:

The functions calloc(), malloc(), and realloc() do not attempt to allocate storage by calling ::operator new().

The function free() does not attempt to deallocate storage by calling ::operator delete().

关于c++ - C++ 编译器一般是 "optimize"malloc 和 free to new and delete 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53502688/

相关文章:

c - 将程序计数器(又名指令指针)重置为 0

c - 调用 Seg Fault 以销毁 malloced 结构

在堆上创建多维结构数组?

c++ - 在 multimap 中,如何获取与给定值关联的键?

c - 在 C 文件中写入矩阵的内容

c++ - #pragma start 和 #pragma exit 的用例

c - 添加到 malloc 数组的值将成为 malloc 数组中的所有值

c - malloc(-1) 返回 NULL 但 malloc(0) 不返回,为什么?你怎么能分配0内存空间

C++ vector 位置设置为 1 而不是 0

c++ - 为什么类型推导对我的集合交集和集合差异调用不起作用?