Describe difference between malloc()/free() & new/delete?, C/C++ Programming

for object, malloc allocates memory in heap however doesn't invoke object's constructor to initialize the object. new allocates memory & also invokes constructor to initialize the object. free() and malloc()  do not support object semantics, does not destruct and construct objects

For example :  string * ptr = (string *)(malloc (sizeof(string))) Are not secure, and does not compute the size of the objects that it construct

The following return a pointer to void int *p = (int *) (malloc(sizeof(int))); int *p = new int;

Are not extensible delete and new can be overloaded in a class "delete" first calls object's termination routine (for example. its destructor) and after that releases the space the object engaged on the heap memory. If an array of objects was developed using new, then delete ought to be told that it is dealing along with an array by preceding the name along with an empty []:-

Int_t *my_ints = new Int_t[10];

...

delete []my_ints;

 

Posted Date: 3/16/2013 3:22:10 AM | Location : United States







Related Discussions:- Describe difference between malloc()/free() & new/delete?, Assignment Help, Ask Question on Describe difference between malloc()/free() & new/delete?, Get Answer, Expert's Help, Describe difference between malloc()/free() & new/delete? Discussions

Write discussion on Describe difference between malloc()/free() & new/delete?
Your posts are moderated
Related Questions

reocord of a student and a function ctotal to calculate the marks of any three subject by using ctotal() function

when a class is defined the compiler will not allocate memory. This is true only for data member not for member function.  As soon as the member function is defined  the require

how c program starts executing?

Prepare data from fixed OCR areas scanned. Project Description: Project is to design software which can use character recognition only on certain areas of scanned pdf's/ jpeg

Employ operator () instead of operator[]. While you have multiple subscripts, the cleanest way to do it is along with operator () instead of with operator[]. The reason is that

Write a program that counts from 0 to 99 and prints these numbers to the terminal ie it prints 00, 01, 02, 03, 04, 05, ....,99. Graphics 1. Write a program in rPeANUt that

for different operation multiple stack

Programming Assignment # 1 C and UNIX   The purpose of this assignment is to get you more familiar with Unix/Linux and those constructs of C that are not part of C++. Write a C