90 likes | 289 Views
Windows 程式設計 ( 使用 C++ / C#). PART 3 徐振家 July 2004. 課程摘要. Part 1 前言 UI 基礎觀念 Part 2 C# Windows Form 程式設計 Part 3 MFC 程式設計 ATL/WTL 程式設計 Part 4 Process and thread control in Win32 native Process and thread control in .Net. MFC 視窗程式設計. VC++ 除錯技巧. 人有失蹄,馬有亂手, 吃芝麻沒有不掉燒餅的 ….
E N D
Windows 程式設計(使用 C++ / C#) PART 3 徐振家 July 2004
課程摘要 • Part 1 • 前言 • UI 基礎觀念 • Part 2 • C# Windows Form 程式設計 • Part 3 • MFC 程式設計 • ATL/WTL 程式設計 • Part 4 • Process and thread control in Win32 native • Process and thread control in .Net
VC++ 除錯技巧 人有失蹄,馬有亂手,吃芝麻沒有不掉燒餅的 …
預防勝於治療 • Code Complete • Writing Solid Code • 三大絕招 • assert • printf • small step dance (extreme programming 的精髓) • Configuration management • 善用 SourceSafe • 利用 tool 追蹤 bug 和需求變動
Memory Leak • Memory leak 是最常見的問題,就是要了一塊 heap 記憶體但卻沒有還回去 • malloc()/free(),new/delete 不成對 • callee allocate / caller 忘了 free • 用到 BSTR 這類系統自己幫你 allocate 的東西,卻忽略了將它們佔用的 memory 清除 • VC++ 提供了內建的 memory leak detection 的功能 • 請參考 MSDN:memory leaks • 你也可以使用如 DevPartner Studio 等進階的工具來幫助你找尋這些問題 • 前提是你們公司要肯花錢買
CRT Memory Leak Detection • 在 .cpp 中加入 #define CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h> • 程式結束時若有 memory leak 則會出現警示 • 實機演練 • 設定 break point 的技巧 • _crtBreakAlloc = nnn; • Memory state 相關操作
MFC Memory Leak Detection • 使用以下的 macro #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif • 使用 CMemoryState和 object dump • 實機演練
使用 MAP File 幫助除錯 • 程式 release 到客戶手上了,但卻發生當機,怎麼找問題? • 實機演練 • 如何產生 map file 與 cod file • 如何反推問題點 • 問題出在 CRT 時,怎麼辦? • 注意:MAP file 的版本控制