Alex Rivera | Logout

What is the difference between new/delete and malloc/free?

Asked 2008-10-27T15:05:30.310
308

What is the difference between new/delete and malloc/free?

Related (duplicate?): In what cases do I use malloc vs new?

Edit
Report

2 Answers

13

In C++ new/delete call the Constructor/Destructor accordingly.

malloc/free simply allocate memory from the heap. new/delete allocate memory as well.

answered 2008-10-27T15:08:36.527
3

new and delete are C++ primitives which declare a new instance of a class or delete it (thus invoking the destructor of the class for the instance).

malloc and free are C functions and they allocate and free memory blocks (in size).

Both use the heap to make the allocation. malloc and free are nonetheless more "low level" as they just reserve a chunk of memory space which will probably be associated with a pointer. No structures are created around that memory (unless you consider a C array to be a structure).

answered 2008-10-27T15:09:31.143

Your Answer