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
C program to print L diagonal triangle: void main() {                 int i=0,j=0;                 int arr[rows][cols];                 for (i=0; i


WAP TO PRINT NUMBERS FROM 1-50 WHICH ARE DIVIDED BY 7 void main () { int a; clrscr (); a=1; while (a { if (a%7==0) printf ("%d\n",a); a++; } ge

C Program for REMOVING CHAR WHICH U WANT void main() {           int i,j;           char a[100],r;           clrscr();           for(i=0;i

write a c++ program to update employee records

Use the program called harris-shell.c and add some code to find the corners in the image checkers.jpg. You should say that a pixel in the image is a corner if it passes the given t

.Develop a two dimensional interactive game with the following features: 1. Use OpenGL (any version you find convenient) 2. The game can either be two player or one player with the

There are formal ways of reducing Boolean expressions in order to minimize the logic circuit. The two elementary ways of minimization are using Boolean expressions/De Morgan Theore

what is spanning tree? explain prims algorithm spanning tree?

Write a ''C'' program to accept any 3 digit integer number from the keyboard and display the word equivalent representation of the given number.