m14_Finding Memory Leaks

m14_Finding Memory Leaks - Finding Memory Leaks Using...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Finding Memory Leaks Using overloaded operator new
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
The new operator and operator new • When allocating memory using new, e.g. Student *ps = new Student(“Yossi Cohen”); int *pi = new int[100]; The new operator (or new[] operator) is called The new ( new[] ) operator – Calls operator new ( operator new[] ) to allocate memory – Calls a constructor (default ctor, for arrays)
Background image of page 2
Overloading operator new • The new operator cannot be overloaded operator new and operator new[] can be overloaded in two ways: – For a given class – As global operators, which will apply for all types and classes for which these operators were not overloaded in the class. • When overloading operator new , one should also overload operator new[]. operator new can be overloaded with extra parameters
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
The delete operator and operator delete • When releasing memory using delete, e.g. Delete ps; delete []pi; The delete operator (or delete[] operator) is called The delete ( delete[] ) operator – Calls the destructor (destructors for arrays) – Calls operator delete ( operator delete[] ) to release memory
Background image of page 4
Overloading operator delete • The delete
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 13

m14_Finding Memory Leaks - Finding Memory Leaks Using...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online