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
Problem #1: plugging the memory leak. When you employ the "normal" new operator, for example Foo* p = new Foo(), the compiler generates some special code to manage the case while t

Simpson's Rule is a more accurate method of numerical integration than the method described in class. Using Simpson's Rule, the integral of a function f between a and b is approxim

Write a function that has an int parameter n, makes an integer mask having the bit 1 at the nth place from the rightmost bit, and returns the mask. For example, when n = 5 is passe

conceptual difference between big o,big thete and big omega

Goal: Design a program that computes square matrix multiplication on GPU using CUDA. Write the code in C. In particular, your implementation should obey the following requiremen

A: A class which is used to traverse through the objects maintained through a container class. There are _ve categories of iterators: output iterators, input iterators, forward ite

What is the specialty in sizeof() operator

HOW THE C PROGRAM CODING IMPLEMENTED DY ITSELF UNDERSTANDING . ALSO HOW I CAN A BECOME A GOOD PROGRAMMER IN C WHAT I DO FOR GOOD PROGRAMMING ,TELL ME HOW C CODING DEVELOP DY ITSELF

write a function that take as parameters an array of integer and its size and return the sum of its value

What is the difference between an external iterator and an internal iterator? Ans) An internal iterator is executed with member functions of the class that has items to step th