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

前端 未结 19 2152
北恋
北恋 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:03

    Rare case to consider using malloc/free instead of new/delete is when you're allocating and then reallocating (simple pod types, not objects) using realloc as there is no similar function to realloc in C++ (although this can be done using a more C++ approach).

提交回复
热议问题