In what cases do I use malloc and/or new?

前端 未结 19 2041
北恋
北恋 2020-11-21 17:41

I see in C++ there are multiple ways to allocate and free data and I understand that when you call malloc you should call free and when you use the

19条回答
  •  没有蜡笔的小新
    2020-11-21 18:06

    Use malloc and free only for allocating memory that is going to be managed by c-centric libraries and APIs. Use new and delete (and the [] variants) for everything that you control.

提交回复
热议问题