我在C++中看到有多种方式来分配和释放数据,我知道当你打电话给malloc你时应该打电话free,当你使用new操作员时你应该配对,delete将两者混合是错误的(例如,调用free()创建的东西)与new操作员),但我不知道何时应该使用malloc/ free何时应该在我的真实世界程序中使用new/ delete.
malloc
free
new
delete
free()
如果您是C++专家,请告诉我您在此方面遵循的任何经验法则或惯例.
c++ malloc memory-management new-operator
c++ ×1
malloc ×1
memory-management ×1
new-operator ×1