Personal study notes of --new / delete

  There are detailed introduced the distinction between new / delete and malloc / free in the previous reprint in here just a little knowledge about the new / delete, I later learned reading coming up.

  new / delete operator is, instead of a function, in fact, when using the new expression, transmitted three steps:

  (1) First, the expression calls the standard library function named "operater new", the allocation of sufficient raw untyped memory to save a specified type of object;

  (2) Next, an operation of this type of constructor initializer configured with the specified objects;

  Pointer (3) Finally, the newly allocated, and returns a pointer to the constructed object.

  Note: Unlike other operator functions, operater new and operator delet not overload new or delete, we can not redefine the behavior of new and delete expressions; however, operator new and operator delete can be overloaded.

  When using delete to delete dynamically allocated objects, such as two steps happened :(: delete p)

  (1) First run appropriate destructor object (p) pointer;

  (2) then release the object by calling the standard library function named operator delete the memory used.

  That, in fact, malloc / free is equivalent to the role of operator new / operator delete is.

Reproduced in: https: //www.cnblogs.com/dpflnevergiveup/p/3295983.html

Guess you like

Origin blog.csdn.net/weixin_33813128/article/details/93268164