C++

Asked • 09/06/19

In what cases do I use malloc vs new?

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 `new` operator you should pair with `delete` and it is a mistake to mix the two (e.g. Calling `free()` on something that was created with the `new` operator), but I'm not clear on when I should use `malloc`/ `free` and when I should use `new`/ `delete` in my real world programs. If you're a C++ expert, please let me know any rules of thumb or conventions you follow in this regard.

1 Expert Answer

By:

Keith B. answered • 09/08/19

Tutor
4.6 (22)

Software Engineer and Math Geek

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.