不可混用使用不同版本 CRT 運行時函式庫的第三方函式庫。換言之,確保程式只有一個 CRT 運行時函式庫實體,即統一採用動態鏈結,並使用同一版本的 CRT 運行時函式庫。
如果考慮到發佈版本的簡易性,程式可能會採用靜態聯結的方式 (視政策而定)。與該程式搭配的動態函式庫,其輸出入皆使用原始型別 ([[wp>primitive data type]]),如: char, int, float, char *。
* [[http://stackoverflow.com/questions/787216/should-i-link-to-the-visual-studio-c-runtime-statically-or-dynamically|Should I link to the Visual Studio C runtime statically or dynamically?]]
* [[https://www.visualstudio.com/en-us/products/vs-2015-product-editions.aspx|Visual Studio 2015]]
====== 使用 ======
* [[http://msdn.microsoft.com/en-us/library/h970wzkb.aspx|How to: Create Multi-Project Solutions]]
* 開啟 Project 之後,先透過 File -> Add -> Existing Project 加入其它工程至當前 Solution。之後可透過於 Solution 按右鍵添加其它工程。
===== 編程技巧 =====
* [[http://msdn.microsoft.com/zh-tw/library/z5hh6ee9.aspx|fopen_s]]
* Files that are opened by fopen_s and _wfopen_s are not sharable. If you require that a file be sharable, use _fsopen, _wfsopen with the appropriate sharing mode constant—for example, _SH_DENYNO for read/write sharing.
* fopen 無法和其它程序共享同一個檔案。須改用 [[http://msdn.microsoft.com/zh-tw/library/8f30b0db.aspx|_fsopen]]
* [[http://stackoverflow.com/questions/906599/why-cant-i-use-fopen|Why can't I use fopen?]]
====== 除錯 ======
* [[http://www.blueocean.com.tw/download/ppt/BO8112-01.ppt|C++範例教學手冊]]
* [[http://www.cprogramming.com/tutorial/visual_studio_tips.html|5 Awesome Visual Studio Debugger Features]]
* [[http://www.codeproject.com/Articles/469416/More-Visual-Studio-Debugging-Tips-for-Native-De|10 More Visual Studio Debugging Tips for Native Development]]
* [[http://msdn.microsoft.com/zh-tw/library/b0084kay.aspx|Predefined Macros]]
* F7 編譯
* F5 以除錯模式執行
* Ctrl + F5 執行
* Debug -> Exceptions -> Win32 Exceptions
* 勾選 c0000005 Access violation
* 及早於例外發生時中斷 debugger,比較好發現問題所在。
* [[http://support.microsoft.com/kb/105675/en-us|First and second chance exception handling]]
* However, if the application is being debugged, the debugger sees all exceptions before the program does. This is the distinction between the first and second chance exception: the debugger gets the first chance to see the exception (hence the name). If the debugger allows the program execution to continue and does not handle the exception, the program will see the exception as usual. If the program does not handle the exception, the debugger gets a second chance to see the exception. In this latter case, the program normally would crash if the debugger were not present.
* [[http://blogs.msdn.com/b/davidklinems/archive/2005/07/12/438061.aspx|What is a First Chance Exception?]]
* [[http://www.codeproject.com/Articles/43682/Writing-a-basic-Windows-debugger|Writing a basic Windows debugger]]
* [[http://msdn.microsoft.com/en-us/library/fsk896zz.aspx|How to: Debug a Release Build]]
* [[http://www.codeproject.com/Articles/548/Surviving-the-Release-Version|Surviving the Release Version]]
* [[http://stackoverflow.com/questions/1762088/common-reasons-for-bugs-in-release-version-not-present-in-debug-mode|Common reasons for bugs in release version not present in debug mode]]
* [[http://stackoverflow.com/questions/312312/what-are-some-reasons-a-release-build-would-run-differently-than-a-debug-build|What are some reasons a Release build would run differently than a Debug build]]
* [[http://www.codeproject.com/Articles/140/Debugging-Release-Mode-Problems|Debugging Release Mode Problems]]
* [[http://accu.org/index.php/journals/1412|Release Mode Debugging]]
* [[http://stackoverflow.com/questions/19817832/what-causes-the-visual-studio-debugger-to-make-some-issues-not-reproducible|What causes the Visual Studio Debugger to make some issues not reproducible?]]
* [[http://www.codemag.com/Article/1208091|Debugging Hard to Reproduce Issues]]
* [[http://eagle-sw.blogspot.tw/2011/10/win7debugview.html|如何在 Win7 使用 DebugView]]
* 如果 Visual Studio Debugger 會導致問題無法複現,使用 DebugView。
* 使用之前,需要修改註冊表。
* [[http://social.msdn.microsoft.com/Forums/en-US/400891dc-bc73-47bb-a20e-f66bc13f275d/difference-between-execution-mode-when-ctrl-f5-is-pressed-and-when-only-f5-is-pressed?forum=vcprerelease|Difference between execution mode when ctrl F5 is pressed and when only F5 is pressed]]
* [[http://stackoverflow.com/questions/11202088/what-is-different-between-visual-studio-f5-ctrlf5-or-running-outside-of-visua|What is different between visual studio F5, ctrl+F5, or running outside of visual studio?]]
* [[http://stackoverflow.com/questions/15638995/what-are-the-negative-consequences-of-turning-debug-heap-off-no-debug-heap-1|What are the negative consequences of turning debug heap off? (_NO_DEBUG_HEAP==1)]]
* [[http://msdn.microsoft.com/en-us/library/vstudio/7sye83ce(v=vs.100).aspx|How to: Specify a Breakpoint Condition]]
* [[http://blogs.msdn.com/b/zainnab/archive/2010/05/03/set-a-simple-breakpoint-condition-vstipdebug0021.aspx|Set a Simple Breakpoint Condition]]
* [[http://www.suodenjoki.dk/us/archive/2010/conditional-breakpoint.htm|Conditional Breakpoint for std::string in Visual Studio 2010]]
* [[http://msdn.microsoft.com/en-us/library/k70yt3e2(v=vs.90).aspx|Debugging Native Code]]
* [[http://msdn.microsoft.com/en-us/library/x98tx3cf(v=vs.90).aspx|Memory Leak Detection and Isolation]]
確認 .pdb 檔需要擺放的位置和欲除錯的 exe 需要擺放的目錄 (查看 *.xml 檔)。
* [[http://www.devmentor.org/articles/crash_dump/crashdump3.php|Debugging a Crash Dump]]
* [[http://stackoverflow.com/questions/12252407/analyzing-crash-dumps-in-visual-studio|Analyzing Crash dumps in Visual Studio]]
* [[https://msdn.microsoft.com/en-us/library/vstudio/d5zhxt22(v=vs.110).aspx|Use Dump Files to Debug App Crashes and Hangs in Visual Studio]]
* Visual Studio -> File -> Open Project,開啟 *.dmp 檔。
* Tools -> Options -> Debugging -> Symbols -> Symbol file (.pdb) locations,指定 *.pdb 檔所在目錄。
* Debug -> Start Debugging
* 如果出現 [[http://stackoverflow.com/questions/16403020/no-symbols-are-loaded-for-any-call-stack-frame-the-source-code-cannot-be-displa|No symbols are loaded for any call stack frame. The source code cannot be displayed]] 訊息,改用 [[https://msdn.microsoft.com/en-us/windows/hardware/hh852365.aspx|WinDbg]] 檢視 crash dump 相關資訊。有可能是 .pdb 檔不匹配 (檔名、時間戳記、校驗碼),導致符號找不到。
* [[https://msdn.microsoft.com/en-us/library/windows/hardware/ff538058(v=vs.85).aspx|Analyzing a User-Mode Dump File with WinDbg]]
* [[https://msdn.microsoft.com/en-us/library/windows/hardware/ff551035(v=vs.85).aspx|Installing Windows Symbol Files]]
* 取得 Windows 模塊的符號,可以看到更清楚的除錯訊息 ([[http://blogs.msdn.com/b/iliast/archive/2006/12/10/windbg-tutorials.aspx|Windbg Tutorials]])。
# 指定 .pdb 檔存放目錄。
$ .symfix c:\myCache
# 下載 .pdb 檔。
$ .reload /f
* [[http://www.codeproject.com/Articles/6084/Windows-Debuggers-Part-A-WinDbg-Tutorial|Windows Debuggers: Part 1: A WinDbg Tutorial]]
* [[http://zishen.blogspot.tw/2011/04/windbgc-exception.html|WinDbg:手把手教你看C++ Exception]]
# 取得例外的完整資訊。
$ !analyze -v
* [[http://blogs.msdn.com/b/oldnewthing/archive/2010/07/30/10044061.aspx|Decoding the parameters of a thrown C++ exception (0xE06D7363)]]
* [[http://www.codeproject.com/Articles/6469/Debug-Tutorial-Part-Beginning-Debugging-Using-CD|Debug Tutorial Part 1: Beginning Debugging Using CDB and NTSD]]
* [[http://www.codeproject.com/Articles/6470/Debug-Tutorial-Part-The-Stack|Debug Tutorial Part 2: The Stack]]
* [[http://www.codeproject.com/Articles/6489/Debug-Tutorial-Part-The-Heap|Debug Tutorial Part 3: The Heap]]
* [[http://www.codeproject.com/Articles/6522/Debug-Tutorial-Part-Writing-WINDBG-Extensions|Debug Tutorial Part 4: Writing WINDBG Extensions]]
* [[http://www.codeproject.com/Articles/6988/Debug-Tutorial-Part-Handle-Leaks|Debug Tutorial Part 5: Handle Leaks]]
* [[http://www.codeproject.com/Articles/7913/Debug-Tutorial-Part-Navigating-The-Kernel-Debugg|Debug Tutorial Part 6: Navigating The Kernel Debugger]]
* [[http://www.codeproject.com/Articles/7919/Debug-Tutorial-Part-Locks-and-Synchronization-Ob|Debug Tutorial Part 7: Locks and Synchronization Objects]]
====== 運行時函式庫 ======
* [[https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx|/MD, /MT, /LD (Use Run-Time Library)]]
* Properties -> Configuration Properties -> C/C++ -> Code Generation
* /MT
* Causes the application to use the multithread, static version of the run-time library.
* 多執行緒、靜態鏈結。
* /MD
* Causes the application to use the multithread-specific and DLL-specific version of the run-time library.
* 多執行緒、動態鏈結。
* [[http://www.davidlenihan.com/2008/01/choosing_the_correct_cc_runtim.html|Choosing the Correct C/C++ Runtime Library]]
* [[wp>Microsoft_Visual_Studio#History|Microsoft_Visual_Studio History]]
* [[http://www.gregcons.com/kateblog/ifvc10isvisualstudio2010whatisvc8.aspx|If VC10 is Visual Studio 2010, what is VC8?]]
* libcmt.lib: 靜態 C 運行時函式庫。
* C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib
* msvcp90.dll -> VC9 -> VS2008
* C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT
* msvcp80.dll -> VC8 -> VS2005
* MSVCR*.DLL: 動態 C 運行時函式庫。
* MSVCP*.DLL: 動態 C++ 運行時函式庫。
* MSVCM*.DLL: 動態 C/C++ 運行時函式庫,供 .NET/Native 混合編程使用。
* LIBCMT: 靜態 C 運行時函式庫。
* [[https://msdn.microsoft.com/en-us/library/abx4dbyh.aspx|CRT Library Features]]
* [[https://msdn.microsoft.com/en-us/library/ms235460.aspx|Potential Errors Passing CRT Objects Across DLL Boundaries]]
* [[http://siomsystems.com/mixing-visual-studio-versions/|Mixing Multiple Visual Studio Versions in a Program is Evil]]
* 程式和其依賴的第三方函式庫最好能使用同一份 CRT 運行時函式庫實體。
* 動態內存分配 (Dynamically Allocated Memory)、全域和靜態變數 (Global and Static Data)、結構和物件傳遞 (Passing C/C++ Objects)、內聯函式和樣板類別與函式 (In-Line Functions, Template Classes, and Template Functions)、檔案和輸出入操作 (File I/O and Operations)、環境變數 (Environment Variables)、系統資源 (Resources) 都和 CRT 運行時函式庫相關。
* 動態內存分配
* 不同 CRT 運行時實體管理各自的堆。所以在不同 CRT 運行時,呼叫 malloc/free 和 new/delete 會有問題。注意! 動態內存分配可能在背後執行,如: C++ vector 的內存分配。另外,不同 CRT 運行時對內存的解讀可能也會有所不同,或是存取時會造成各種錯誤。
* 全域和靜態變量
* 不同 CRT 運行時有各自的靜態變量。如: strtok 的實現有靜態變量,在不同 CRT 運行時調用 strtok 會有問題,因為其中的靜態變量不同步。
* 結構和物件傳遞
* C++ 物件其實現,有可能會使用到動態內存分配。另外,不同 CRT 運行時對內存的解讀可能也會有所不同,不論是傳值 (passed by value) 或是傳參考 (passed by reference)。
* 內聯函式和樣板類別與函式
* 內聯函式和樣板類別與函式,其實體化在不同 CRT 運行時會有不同。
* 檔案和輸出入操作
* 在不同 CRT 運行時,呼叫 fopen、fclose 和 freopen 會有問題。
* C++ 的 iostream 是模板類別,其實體化在不同 CRT 運行時會有不同。
* 環境變數
* 每一個 CRT 運行時實體管理各自的環境變數,彼此之間不同步。在不同 CRT 運行時,呼叫 getenv 和 putenv 會有問題。
* 系統資源
* [[http://stackoverflow.com/questions/1947822/runtime-issues-while-mixing-libraries-from-different-versions-of-visual-studio|Runtime Issues While Mixing Libraries from Different Versions of Visual Studio]]
* [[http://stackoverflow.com/questions/25284513/check-what-run-time-static-library-or-dll-uses|check what run-time static library or dll uses]]
* [[http://www.codeproject.com/Articles/22642/What-Every-Computer-Programmer-Should-Know-About-W|What Every Computer Programmer Should Know About Windows API, CRT, and the Standard C++ Library]]
* Can STL vector cross DLL boundary
* STL container heap allocate/free across DLL memory space
* [[http://stackoverflow.com/questions/11140057/exposing-stdvector-over-a-dll-boundary-best-practice-for-compiler-independen|Exposing std::vector over a dll boundary - best practice for compiler independence]]
* [[http://stackoverflow.com/questions/5661738/how-can-i-use-standard-library-stl-classes-in-my-dll-interface-or-abi|How can I use Standard Library (STL) classes in my dll interface or ABI?]]
* [[http://stackoverflow.com/questions/17885060/passing-reference-to-stl-vector-over-dll-boundary|Passing reference to STL vector over dll boundary]]
* [[http://stackoverflow.com/questions/16362415/could-i-ignore-c4251-warning-in-this-case|Could I ignore C4251 warning in this case?]]
* [[http://lektiondestages.blogspot.tw/2011/08/writing-dll-containing-c-classes.html|Writing a DLL containing C++ classes]]
* [[http://stackoverflow.com/questions/5637662/calling-functions-with-stl-parameters-from-a-shared-library|calling functions with STL parameters from a shared library]]
* [[http://stackoverflow.com/questions/13864510/exporting-stl-class-from-dll-why-is-there-no-warning-from-the-return-type|Exporting STL class from DLL - why is there no warning from the return type?]]
* Exposing C++ objects by value requires the client of your DLL to use the same CRT so that objects that are created in the DLL can be safely destroyed by the client app. And the other way around. Which requires that these modules use the same heap.
* 即客戶端和動態函式庫共享同一個版本的 CRT。
* [[http://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx|Dynamic-Link Library Best Practices]]
* [[http://blog.csdn.net/wingeek/article/details/4237703|[Windows编程] 开发DLL必读《Best Practices for Creating DLLs》]]
* [[http://programmers.stackexchange.com/questions/176681/did-c11-address-concerns-passing-std-lib-objects-between-dynamic-shared-librar|Did C++11 address concerns passing std lib objects between dynamic/shared library boundaries? (ie dlls and so)?]]
* [[wp>Component Object Model]]
* [[http://tldp.org/HOWTO/C++-dlopen/|C++ dlopen mini HOWTO]]
* [[http://support.microsoft.com/kb/172396/en-us|You may experience an access violation when you access an STL object through a pointer or reference in a different DLL or EXE]]
* [[http://support.microsoft.com/kb/168958/en-us|How to export an instantiation of a Standard Template Library (STL) class and a class that contains a data member that is an STL object]]
* [[http://blog.csdn.net/lewutian/article/details/6786193|DLL中传递STL参数,vector对象作为dll参数传递等问题]]
* [[http://social.msdn.microsoft.com/Forums/vstudio/en-US/db747276-2667-41ab-9f39-16d9972559e7/how-to-make-a-stl-container-cross-the-dll-boundary|How to make a STL container cross the DLL boundary?]]
* [[http://msdn.microsoft.com/zh-tw/library/ys6cfhhh.aspx|_CrtIsValidHeapPointer]]
* 小結: EXE 和 DLL 必須以 DLL 方式鏈結 MS CRT,以確保只有一份 CRT 控管 STL 物件所在的堆 (heap)。
If a dynamic-link library (DLL) contains a static link to the run-time library, it has its own instance of the run-time heap, and therefore its own heap, independent of the application's local heap.
* [[http://stackoverflow.com/questions/17885060/passing-reference-to-stl-vector-over-dll-boundary|Passing reference to STL vector over dll boundary]]
* [[http://programmers.stackexchange.com/questions/176681/did-c11-address-concerns-passing-std-lib-objects-between-dynamic-shared-librar|
Did C++11 address concerns passing std lib objects between dynamic/shared library boundaries? (ie dlls and so)?]]
* [[http://stackoverflow.com/questions/2538103/how-to-call-a-function-from-a-shared-library|How to call a function from a shared library?]]
====== 例外處理 ======
* [[https://support.microsoft.com/en-us/kb/185294|PRB: Exception Code 0xE06D7363 When Calling Win32 SEH APIs]]
* All Visual C\+\+ exceptions thrown from code generated by the Microsoft Visual C\+\+ compiler contain this error code.
* [[http://blogs.msdn.com/b/oldnewthing/archive/2010/07/30/10044061.aspx|Decoding the parameters of a thrown C++ exception (0xE06D7363)]]
* [[http://www.databaseforum.info/2/8/653cac331d15c885.html|0xE06D7363: Microsoft C++ Exception - how to catch]]
catch (_com_error& ex)
{}
* [[http://crashrpt.sourceforge.net/docs/html/exception_handling.html|About Exceptions and Exception Handling]]
* [[http://www.codeproject.com/Articles/207464/Exception-Handling-in-Visual-Cplusplus|Effective Exception Handling in Visual C++]]
* 如果 SEH 例外被丟出而未被處理,會跳出視窗 ([[wp>Dr. Watson (debugger)|Dr. Watson]]) 顯示相關訊息。
* [[https://msdn.microsoft.com/en-us/library/xwtb73ad.aspx|cannot use __try in functions that require object unwinding]]
* [[http://stackoverflow.com/questions/3786647/difference-between-a-c-exception-and-structured-exception|Difference between a C++ exception and Structured Exception]]
* [[https://msdn.microsoft.com/en-us/library/4t3saedz(v=vs.80).aspx|C++ Exception Handling]]
* 例外只會透過 throw 陳述句產生。此機制由 C 運行時函式庫提供。
* [[https://msdn.microsoft.com/en-us/library/windows/desktop/ms680657(v=vs.85).aspx|Structured Exception Handling]]
* 每道指令皆可能發生例外。此機制由 Windows 作業系統本身提供。
* [[http://syprog.blogspot.tw/2011/10/windows-structured-and-vectored.html|Windows Structured and Vectored Exception Handling Mechanisms]]
* [[wp>Microsoft-specific exception handling mechanisms]]
* [[https://msdn.microsoft.com/en-us/library/windows/desktop/ms681420(v=vs.85).aspx|Vectored Exception Handling]]
* VEH 是 SEH 的擴展,於 Windows XP 引入。發生例外時,VEH 優先於 SEH 被調用。
* [[https://msdn.microsoft.com/en-us/library/969zc1ac.aspx|Error Handling (CRT)]]
* C 運行時函式庫自身提供的例外處理機制。
* [[https://msdn.microsoft.com/en-us/library/xdkz3x12.aspx|C++ Signal Handling]]
* 訊號 (signal) 在 Linux 系統中是例外處理的主要機制,但是在 Windows 較少使用。
* [[https://www.microsoft.com/msj/0197/exception/exception.aspx|A Crash Course on the Depths of Win32™ Structured Exception Handling]]
* 本文講述 Windows 提供的 SEH 運作原理,再講述編譯器基於前述機制所提供的 SEH。
* [[http://www.cnblogs.com/awpatp/archive/2010/06/15/1758763.html|[经典文章翻译]A Crash Course on the Depths of Win32 Structured Exception Handling]]
* [[http://vicchina.51.net/research/other/seh/sehadvance.htm|深入研究 Win32 结构化异常处理]]
* [[http://blog.csdn.net/yuzl32/article/details/5347442|Win32 结构化异常处理(SEH)探秘]]
* [[https://msdn.microsoft.com/en-us/magazine/cc301714.aspx|Under the Hood: New Vectored Exception Handling in Windows XP]]
* [[http://www.pediy.com/kssd/pediy09/pediy09-233/New%20Vectored%20Exception%20Handling%20in%20Windows%20XP.pdf?attachmentid=8311&d=1188905003|Windows XP 中的新型向量化异常处理]]
* [[https://msdn.microsoft.com/en-us/library/1deeycx5(VS.80).aspx|/EH (Exception Handling Model)]]
* Specifies the model of exception handling to be used by the compiler and destroys C\+\+ objects that will go out of scope as a result of the exception. If /EH is not specified, the compiler will catch structured and C\+\+ exceptions, but will not destroy C\+\+ objects that will go out of scope as a result of the exception.
* 不指定 /EH 時,不做 unwinding。即針對棧上的物件,不會調用其解構子。
* /EHsc
* Use /EHs to specify the synchronous exception handling model (C\+\+ exception handling without structured exception handling exceptions).
* If used with s (/EHsc), catches C\+\+ exceptions only and tells the compiler to assume that extern C functions never throw a C\+\+ exception.
* /EHa
* Use /EHa to specify the asynchronous exception handling model (C\+\+ exception handling with structured exception handling exceptions).
* [[https://msdn.microsoft.com/en-us/library/7f10tsf4(v=vs.100).aspx|Exception Handling: Default Synchronous Exception Model]]
* In previous versions of Visual C\+\+, the C\+\+ exception handling mechanism supported asynchronous (hardware) exceptions by default. Under the asynchronous model, the compiler assumes any instruction may generate an exception.
With the new synchronous exception model, now the default, exceptions can be thrown only with a throw statement.
* 在非同步例外模行中 (asynchronous exception model),編譯器必須假設每道指令皆可能發生例外。
* 在同步例外模型中 (synchronous exception model),例外只能透過 throw 陳述式丟出。編譯器可以減少相關代碼產生。
* [[https://msdn.microsoft.com/en-us/library/windows/desktop/ms679353(v=vs.85).aspx|Frame-based Exception Handling]]
* [[http://blogs.msdn.com/b/oldnewthing/archive/2013/03/20/10403718.aspx|The x86 architecture is the weirdo: Structured exception handling]]
* [[http://stackoverflow.com/questions/27926085/how-can-i-register-a-structured-exception-handler-in-assembly-on-x86-64-architec|How can I register a structured exception handler in assembly on x86-64 architecture on Windows?]]
* [[http://vrt-blog.snort.org/2014/06/exceptional-behavior-windows-81-x64-seh.html|Exceptional behavior: the Windows 8.1 X64 SEH Implementation]]
* 例外處理機制基本上有兩種實現方式: frame-based (stack-based) 和 table-based。Windows x86 採用前者; Windows x86_64 採用後者 ([[https://msdn.microsoft.com/en-us/library/1eyas8tf(v=vs.80).aspx|Exception Handling (x64)]])。其它編譯器大部分採用後者。
try {
// guarded body of code
}
except (filter-expression) {
// exception-handler block
}
* frame-based: 首先會為 try 於棧上建立 EXCEPTION_REGISTRATION 結構,將其串入 linked list of exception handlers。離開 try 的同時,將對應的EXCEPTION_REGISTRATION 結構移出 linked list of exception handlers。EXCEPTION_REGISTRATION 結構中的回調函式,對應於 except 中的 filter-expression。此為基本概念,實際做法有所不同。簡單來說,例外處理相關的資料結構創建於棧上,故稱 frame-based。
* table-based ([[http://mentorembedded.github.io/cxx-abi/abi-eh.html|Itanium C++ ABI: Exception Handling]]): 在沒有例外發生的情況下,沒有在棧上創建資料結構的開銷,又稱 zero-cost。
* [[http://www.nynaeve.net/?p=114|Programming against the x64 exception handling support, part 7: Putting it all together, or building a stack walk routine]]
* [[exception handling]]
====== 優化 ======
* [[http://msdn.microsoft.com/en-us/library/xct6db7f(v=vs.90).aspx|Walkthrough: Using Profile-Guided Optimizations]]
====== Profile ======
* [[http://msdn.microsoft.com/en-us/library/fda2bad5(v=vs.90).aspx|Visual Studio Team System]]
* [[http://msdn.microsoft.com/en-us/library/z9z62c29(v=vs.90).aspx|Analyzing Application Performance using Profiling Tools]]
* [[http://www.cppblog.com/mymsdn/archive/2010/04/01/111307.html|用事实说话,C++ Profiler(Visual Studio 2008)]]
* [[https://atsung.wordpress.com/2009/06/02/visual-studio-2008-sp1-team-system-profiler-causes-blue-screen-on-intel-core-i7-processor/|Visual Studio 2008 (SP1) Team System Profiler causes blue screen on Intel Core i7 processor]]
* [[http://support.microsoft.com/kb/958842/en-us|KB958842: FIX: A Stop error or a crash occurs on the operating system when you profile an application by using Visual Studio 2008 Service Pack 1]]
* 先對目標程序做 Sampling。
* [[http://msdn.microsoft.com/en-us/library/ms182384(v=vs.90).aspx|How to: Attach and Detach the Profiler to Running Processes]]
* You can use this method to profile a process when you want to avoid gathering data about application load time, or to monitor the performance of a process after it reaches a specific state.
* 再針對目標程序有針對性的做 Instrument。若是針對全局插樁,則蒐集到的資訊有可能會塞爆硬盤。
* [[http://msdn.microsoft.com/en-us/library/cc470663(v=vs.90).aspx|How to: Limit Instrumentation to Specific Functions]]
* 分析數據。
* [[http://msdn.microsoft.com/en-us/library/ms182389(v=vs.90).aspx|Analyzing Profiling Tools Data]]
* [[http://msdn.microsoft.com/en-us/library/dd255356(v=vs.90).aspx|Summary View - Profiler Instrumentation Data]]
* Functions with the Most Individual Work
* A list of the functions that directly executed at the top of the call stack for the longest time. Time spent in child functions is not included.
* 不考慮子函式花費時間,取在棧頂端花費時間最多的函式。
* Functions Taking the Longest
* A list of the functions that were executing on the call stack for the longest times. Time spent in calls to child functions is included.
* 考慮子函式花費時間,取花費時間最多的函式。
* [[http://msdn.microsoft.com/en-us/library/ms182398(v=vs.90).aspx|Walkthrough: Profiling Applications]]
* Profiling by Using the Sampling Method
*
It is recommended to use a release build to detect performance problems in your application.
A release build is recommended for profiling because a debug build has additional information compiled into it that may adversely affect performance and fail to illustrate performance issues accurately.
A release build does not automatically give you symbol information. To configure your build so symbol information is visible in profiler performance reports, see /Z7, /Zi, /ZI (Debug Information Format) and How to: Reference Windows Symbol Information.
* 目標程序需要有相應的 [[http://msdn.microsoft.com/en-us/library/yd4f8bd1(v=vs.90).aspx|PDB 檔]]。
* Profiling by Using the Instrumentation Method
* [[http://posted-stuff.blogspot.tw/2010/06/visual-studio-profiling-problems.html|Visual Studio 2008 & profiling problems]]
* The executable that is to be profiled needs to have been linked with the /profile switch, which can be done with a simple recompile after changing the corresponding configuration option.
* [[http://blogs.msdn.com/b/profiler/archive/2010/01/14/prf0025-no-data-was-collected-why-is-that.aspx|PRF0025: No data was collected – why is that?]]
* [[http://blogs.msdn.com/b/profiler/archive/2008/07/08/excluding-small-functions-from-instrumentation.aspx|Excluding Small Functions From Instrumentation]]
* The first benefit of this feature is reduced instrumentation probe execution overhead.
* The second benefit is reduced profile data file (.vsp) size.
* With this feature enabled, it’s important to note that the time spent executing a small function does not just disappear.
* [[http://blogs.msdn.com/b/ianhu/archive/2007/07/17/the-visual-studio-profiler-data-collection-control-part-1-excluding-application-startup-time.aspx|The Visual Studio Profiler Data Collection Control Part 1: Excluding Application Startup Time]]
* 專注在程序特定區塊做調優。
* [[http://www.drdobbs.com/parallel/overlooked-essentials-for-optimizing-cod/228701528|Overlooked Essentials For Optimizing Code]]
* [[http://coolshell.cn/articles/2967.html|代码优化概要]]
* 花費時間多的函式
* 被調用次數多的函式
* [[http://blogs.msdn.com/b/profiler/archive/tags/vs2008/|Visual Studio Profiler Team Blog]]
====== 命令行工具 ======
* [[http://superuser.com/questions/285984/how-do-i-full-screen-my-cmd|How do I full-screen my CMD?]]
* [[http://superuser.com/questions/135214/using-cd-command-in-windows-command-line-cant-navigate-to-d|Using cd Command in Windows Command Line, Can't Navigate to D:\]]
* [[http://stackoverflow.com/questions/13428758/readelf-utility-for-visual-studio-c-abi-and-vs-compiled-objects|readelf utility for Visual Studio C++ ABI and VS compiled objects?]]
PS C:\> DUMPBIN /ARCHIVEMEMBERS libboost_graph-vc80-mt-1_57.lib
PS C:\> LIB libboost_graph-vc80-mt-1_57.lib /EXTRACT:bin.v2\libs\graph\build\msvc-8.0\release\address-model-32\link-static\threading-multi\read_graphviz_new.obj
# 或是直接用 Notepad 開啟 read_graphviz_new.obj,搜尋 manifestdependency,後面的字串包含其鏈結 C 運行時函式庫的版本。
PS C:\> DUMPBIN /DIRECTIVES read_graphviz_new.obj
* [[https://msdn.microsoft.com/en-us/library/c1h23y6c.aspx|DUMPBIN]]
* [[https://msdn.microsoft.com/en-us/library/9w99735w.aspx|/ARCHIVEMEMBERS]]
* 列出 *.lib 檔裡面包含的目的檔。
* [[https://msdn.microsoft.com/en-us/library/7ykb2k5f.aspx|LIB]]
* [[https://msdn.microsoft.com/en-us/library/889z8z58.aspx|Extracting a Library Member]]
====== MSBuild ======
* [[http://codingcockerel.co.uk/2008/04/15/automating-the-build-with-msbuild/|Automating the build with MSBuild]]
* [[http://codingcockerel.co.uk/2008/04/20/automating-the-build-with-msbuild-part-two/|Automating the build with MSBuild (part two)]]
* [[http://codingcockerel.co.uk/2008/05/05/automating-the-build-with-msbuild-part-three/|Automating the build with MSBuild (part three)]]
* [[http://blogs.microsoft.co.il/arik/2011/05/17/speed-up-visual-studio-builds/|Speed up Visual Studio Builds]]
====== 術語 ======
* [[http://superuser.com/questions/529400/how-does-progra1-path-notation-work|How does “PROGRA~1” path notation work?]]
* [[wp>8.3 filename]]
* [[http://stackoverflow.com/questions/6433161/what-does-psz-stand-for-in-pszbuffer-or-the-similar|What does “psz” stand for in pszBuffer or the similar?]]
* **p**ointer to **s**tring, **z**ero-terminated
* 近似 char *
====== 其它 ======
* [[http://www.zachburlingame.com/2011/05/resolving-redefinition-errors-betwen-ws2def-h-and-winsock-h/|Resolving Redefinition Errors Betwen ws2def.h and winsock.h]]
* [[http://stackoverflow.com/questions/1372480/c-redefinition-header-files|C++ Redefinition Header Files]]
* [[http://stackoverflow.com/questions/11040133/what-does-defining-win32-lean-and-mean-exclude-exactly|What does #defining WIN32_LEAN_AND_MEAN exclude exactly?]]
* [[http://msdn.microsoft.com/en-us/library/ms173704.aspx|nonstandard extension used: enum 'enum' used in qualified name]]
namespace MyNameSpace {
enum MyEnum {
E1
};
MyNameSpace::E1; // ok
MyNameSpace::MyEnum::E1; // warning
};
* [[http://stackoverflow.com/questions/6320995/why-i-can-not-cout-a-string|why I can not cout a string?]]
* [[http://stackoverflow.com/questions/4437753/how-to-optimize-building-speed-in-visual-studio-2008|How to optimize building speed in visual studio 2008]]
* [[http://stackoverflow.com/questions/567757/how-do-i-distinguish-between-binary-and-text-files|How do I distinguish between 'binary' and 'text' files?]]
* [[http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/BitOp/asciiBin.html|Ascii vs. Binary Files]]
* [[http://stackoverflow.com/questions/229924/difference-between-files-writen-in-binary-and-text-mode|Difference between files writen in binary and text mode]]
* [[https://www.securecoding.cert.org/confluence/display/seccode/FIO14-C.+Understand+the+difference+between+text+mode+and+binary+mode+with+file+streams|FIO14-C. Understand the difference between text mode and binary mode with file streams]]
* 文字檔基本上也是二進制檔。只能判斷檔案的編碼是否符合已知的文字編碼,以此來區分文字和二進制檔。
====== Q & A ======
* [[http://support.microsoft.com/?scid=kb%3Ben-us%3B148652&x=13&y=8|A LNK2005 error occurs when the CRT library and MFC libraries are linked in the wrong order in Visual C++]]
* [[http://mqjing.blogspot.tw/2008/11/c-dllmain12-already-defined-in.html|[C++] 我發誓! 我什麼都沒動, 原本可以動的程式, 竟然幾天後就不行了]]
* 命令行參數無作用
* 當 solution 中,有數個 project 時,可能 startUp project 設錯。選擇正確的 project,按右鍵 -> Set as StartUp Project。
* [[https://svn.boost.org/trac/boost/ticket/9554|read_graphviz example code crashes]]
* 有可能是 C 函式庫的問題。有沒有可能是 project 和 boost 函式庫所鏈結到 C 函式庫有所不同?
* [[https://support.microsoft.com/en-us/kb/126709|R6016 - not enough space for thread data]]
====== 外部連結 ======
* [[Windows Research Kernel]]
* [[http://www.wholetomato.com/default.asp|Visual Assist]]