gpt4 book ai didi

c++ - 为什么我们不能释放由 new 分配的内存?

转载 作者:太空狗 更新时间:2023-10-29 23:21:22 25 4
gpt4 key购买 nike

我知道 free() 不会调用析构函数,但是除了成员变量不能被正确析构之外,还会导致什么?

此外,如果我们删除一个由malloc分配的指针怎么办?

最佳答案

new 是否在后台使用 malloc 是实现定义的。将 newfreemallocdelete 混合 could cause a catastrophic failure at runtime if the code was ported to a new machine, a new compiler, or even a new version of the same compiler .

关于c++ - 为什么我们不能释放由 new 分配的内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5752081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com