What are the two steps that happen while i say delete p?, C/C++ Programming

A: N delete p is a two-step procedure: it calls the destructor, and then releases the memory. The code developed for delete p is functionally similar to this (supposing p is of type Fred*):

// Original code: delete p;

if (p != NULL) { p->~Fred(); operator delete(p);

}                                              

The statement p->~Fred() calls the destructor for the Fred object pointed to by p.

The statement operator delete(p) calls memory deallocation primitive, void operator delete(void* p). This primitive is same in spirit to free(void* p). (Note down, however, that these two are not interchangeable; for example there is no guarantee that the two memory deallocation primitives even employ the same heap!)

 

Posted Date: 3/19/2013 8:40:45 AM | Location : United States







Related Discussions:- What are the two steps that happen while i say delete p?, Assignment Help, Ask Question on What are the two steps that happen while i say delete p?, Get Answer, Expert's Help, What are the two steps that happen while i say delete p? Discussions

Write discussion on What are the two steps that happen while i say delete p?
Your posts are moderated
Related Questions
Linear search in array - C program: Write a program in c to define a linear search in array. void main()                 {                 clrscr();

Need Payment Gateway Integration Expert Project Description: I am seeking for expert payment gateway integration. You must have done or have experience with integrating me

C Program to FIND VOWELS AND REMOVE VOWELS void main() {           char s[100],s1[100];           int i,j,k=0;           clrscr();           printf("ENTER ANY S

differentiate between inbuilt and user defined functions

Write a program to create a binary file and store the following data "hello", 0x0030,'1', 1.234  Using visual studio examine the binary file and note how the day is stored   Answe

Default argument: When the argument is missing then the function will read the default value of the missing argument.  To make use of default argument functionality the argu

Project Description:  LOOKING TO DEVELOP A ONLINE POKER Web Application. WEBSITE WILL BE DEVELOPED OVER THE NEXT 6 MONTHS Duration & WILL REQUIRE FULL SOFTWARE CODING OF WEB

Create a user-defined data structure (struct) called Node that represents a node within a linked list where the "data" stored in each node is a pointer to a Car object.    a) Wr

Illustration of Plot function: To be more common, the script could prompt the user for the time and temperature, instead of just assigning the values. Then, the axis function

The for Loop For loop is the controlled form of loop. The general format of this : for( initialize ; test ; update)                  {                     statements;