11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

390Part VI: The Part of TensBut what if your program is too slow and you want to spiff it up? Fortunately,Dev-C++ (and most other C++ environments) offers something known as aprofiler. This nifty little tool watches your program to determine where it’sspending its time. Once you know that, you can decide where to spend yourvaluable coding time.To enable Profiling, I chose Tools➪Compiler Options. Then I selected Settingsand Code profiling to set Generate Profiling Info for Analysis.I then added the following edited version of the DeepCopy program fromChapter 18://// DeepCopy - provide a program to profile//#include #include #include #include #include using namespace std;class Person{public:Person(char *pN){pName = new char[strlen(pN) + 1];if (pName != 0){strcpy(pName, pN);}}Person(Person& p){pName = new char[strlen(p.pName) + 1];if (pName != 0){strcpy(pName, p.pName);}}~Person(){if (pName != 0){delete pName;pName = 0;}}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!