寧可備而不用,不可用而不備,這邊講的是Debugger使用的工具,其他Memory Check跟Performance turing就沒列出了。
有更新再補完
Windows
Unix
- voltron GDB/LLDB的Frontend
寧可備而不用,不可用而不備,這邊講的是Debugger使用的工具,其他Memory Check跟Performance turing就沒列出了。
有更新再補完
這功能很有用,SVN的時代常常使用,不過在Git上就忘了怎麼用。
看到Stackoverflow的資料紀錄一下。
首先,先查詢某個檔案的Commit log。
1 | $ git log -- [filename] |
以下是一個示範
1 | $ git log --pretty=oneline --abbrev-commit -- README.md |
接著就可以用git diff來比較兩個commit之間的差異。
1 | $ git diff {version1} {version2} -- [filename] |
如果我們要看README.md的前一個版本跟現在的版本差異,就能這樣操作
1 | $ git diff acb9f89 HEAD -- README.md |
有個好的GUI果然比較有用,這些技術以備不時之需。
這一組API雖然在Coding上不會直接用上,不過要實做Coroutine,模擬Exception的時候,總部會少了他。紀錄一下>
setjmp/longjmp很像Goto,不過比Goto更強,可以跳躍至任何地方,Goto不能跳躍至函數外層。直接看例子吧。
1 | #include <stdio.h> |
叢書出的結果我們可以猜到程式怎麼運作
1 | second |
我對Rust也是初學者的狀態,以下是從A 30 minute introduction to Rust看來的,既然Rust被定位成System programming language,難免要拿來跟C++比一比。看看Ruat友什麼特別之處。
在C/C++,很簡單可以寫出這樣的程式碼。
1 | int* dangling(void) |
由於現在CPU對於Memory Byte Algined的處理較好,所以很多資料結構的擺法都會偏向於4 Byte Alginment的方式進行。例如
1 | struct string_t { |
string_t的大小為8,而非眾人想像中的5,如果要強制讓這個Structure大小為5的話,可以採用以下這種方式。
1 | // GCC Style |
如果不用這兩種方式的話,如何使用投機的方式來減少分配
1 | #include <stddef.h> |
其實上面那個char val[1]也是不需要的,在支援zero array之後,用這個方式更簡單
1 | struct string_t { |
簡單做一下筆記。
這篇是Concurrency in C++11的部份筆記,先寫有關C++11標準的部份。
future, promise被加入C++11,大概等同於C#的Task或是Java8的Future。
以讀寫一個檔案作為範例
1 | vector<char> readFile(const string& inPath) |
如果要拷貝一個檔案,可以這樣寫。
1 | size_t sync_copyFile(const string& inFile, const string& outFile) |
這樣寫得問題在於,讀寫都是同步動作。如果檔案一大,就什麼事都不用做了。如何使用Multithread來感善動作。
顧名思義,提供函數一部分的參數。變成一個新的函數。
最簡單的例子就像這樣
1 | int sub(int a, int b) |
當然上面這種寫法復用度並不高,於是在C++11把bind跟function納入標準配備之後,可以寫成這樣。
1 | std::function<int(int)> sub2 = std::bind(sub, std::placeholders::_1, 2); |
有時間再來討論bind跟function。
不過就可讀性來說,Pyhton版的強多了
1 | import functools |
Currying是為了解決不一樣的問題
假設一個函數有多個參數,把他轉化成多個只有一個參數的函數組合。
用C++11的Lambda Expression來做示範。
1 | std::function<int(int)> add2(int a) |
基本上PCurrying可以實現一部分Partion Application的應用。不過以上麵的sub2
為例,Currying在這邊就不是用。
更清楚的描述可以看What is the difference between currying and partial application