Saturday, 9 February 2013

What are the differences between new and malloc ???

The Main difference between new and malloc is 
- new invokes the object's constructor and
the corresponding call to delete invokes the object's destructor.

- new is type-safe, while malloc returns objects of type VOID*
- new is an operator and can be overloaded, malloc is a function and cannot be overloaded
- new[ ]  allocates arrays,and it's more intuitive than malloc
- new throws an exception on error while malloc returns NULL and gives error no
- malloc can allocate an N byte chunk of memory, while new must be asked to allocate an array of, say, char
- malloc-derived allocations can be resized via realloc, new-derived allocations cannot be resized

Although it is legal for new and malloc to be implemented using different memory allocation algorithms,
On most systems new is internally implemented using malloc, yielding no system-level difference.
 eBay Ad:
  Let's Take A Look at  Online Mega Store; ebay


Post a Comment