answersLogoWhite

0

New and delete are akin to malloc and free, respectively, in C. Although both malloc and free are still available in C++ (for backward compatibility and interoperability with C-style code), the new and delete operators are much simpler to use because the allocation and deallocation of all dynamic memory consumed by an object is handled by the object's own constructors and destructors. Thus there is no need to calculate how much memory to allocate; the new operator can work that out all by itself, based upon the class of object being instantiated, and the object itself can allocate/deallocate any additional dynamic memory as and when it actually requires it.

This mechanism of construction/destruction allows highly complex dynamic objects and object hierarchies to be instantiated at will with just a single call to the new operator. Each object takes care of itself (as do all embedded objects and/or base classes of the object), thus all the programmer has to do is instantiate and delete an object as and when required.

User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering
Related Questions

What will happen if you allocate memory using new and free it using free or allocate sing calloc and free it using delete?

The C++ new uses malloc internally to allocate memory and the C++ delete uses free internally to revoke memory. However, they are not interchangeable and so memory allocated with new MUST be revoked with delete. If you mix them up, you will have a memory leak! Haya.


How do you delete received messages in facebook?

In Facebook there is a notation for new messages. After viewing these messages it is possible to delete them individually or return to the list and delete all. This is done by using the corner x.


Write an Algorithm to delete a last element from the array?

// Assuming you dynamically allocated this array using "new"... delete array[arraysize - 1]; arraysize--;


Assuming an emty list what operations are used to delete and insert a data?

Delete is not possible for an empty list, insert is something like this: Create a new list-element. Register it as the first element of the list. Register it as the last element of the list.


How do I delete a password recall from internet explorer?

Click on password (at beginning) and delete it using delete key. Type new password in. Message will say already have password stored co you want to change. hope this helps.


Add two numbers in pointer in using c plus plus?

int* a = new int(40); int* b = new int(2); int x = *a + *b; // x = 42 delete b; delete a;


Program for new and delete operator using c plus plus?

#include<iostream> struct object { int m_data; }; void main() { object obj=new object; obj.m_data = 42; delete( obj ); return( 0 ); }


What is the purpose of using leveling compound in a flooring project?

The purpose of using leveling compound in a flooring project is to create a smooth and even surface for installing new flooring materials.


Why use new and delete operator overloading in c plus plus?

one reason to use new and delete operator overloading in c++ is when you are using your own memory manager code. when the user of your code calls the new keywork, your memory manager code can allocate memory.


When using the data form dialog box you can edit or delete the selected record or use the same dialog box to add a new what?

Add a new record.


Write c plus plus program for new and delete operator using class?

#include<iostream> class foo{ int m_data; }; int main() { foo* p=new foo; delete( foo), foo=NULL; return(0); }


Get rid of your homework on mathletics?

hay in the url bar where it says courseid delete one of the letters and refresh using the new url