+ 1

What is difference between new and malloc()?

If you're a C++ expert, please let me know any rules of thumb or conventions you follow in this regard.

28th Nov 2017, 7:25 AM
Waqas Ahmed
Waqas Ahmed - avatar
1 Antwort
+ 3
For the developer, the biggest and most important difference is that new will call an object's constructor, while malloc will not. Similarly, delete will call the destructor, while free will not. Free also cannot be used on memory allocated new, and vise versa. In general the only usual reason to use malloc is if you are working with legacy code or overloading the `new` operator.
28th Nov 2017, 8:59 AM
aklex
aklex - avatar