动态内存分配需要注意什么?

What are the things need to be taken care while dynamic memory allocation?

当我使用malloc()new分配内存时,有时会出现运行时间错误,如何避免这些错误?

malloc(),你需要free()

new,你需要delete

new [],你需要delete []

任何其他组合都是未定义的行为。

此外,newnew [] 实际上在分配的内存中构造对象(delete / delete[] 调用其析构函数),而 malloc() / free() 不这样做——它们只处理内存,而不是对象。

鉴于所提供的(缺乏)信息,我能帮到的就这么多了。