原创 傳遞參數給線程函數
創建線程時函數參數默認直接拷貝?不一定 按照參考文獻[1]的說法,傳遞參數給線程函數的時候參數會以默認的方式被複制到內部存儲空間。實際上,在Microsoft Visual Studio Professional 2017實驗環境
原创 Thread Guard
兩種方式實現的用類管理線程的join。 RAII Thread Guard 通過引用來直接管理線程。 #include <thread> #include <iostream> class Stomach { public:
原创 線程入口函數
任何callable target – functions, lambda expressions, bind expressions, or other function objects, as well as pointers
原创 轉移線程的所有權
std::thread和std::unique_ptr,std::fstream、std::ifstream、std::ofstream等流一樣只可轉移move所有權,不可複製copy。 #include <thread> #in
原创 超額訂閱oversubscription
如果實際線程數大於硬件支持的線程數,則出現超額訂閱oversubscription,上下文切換將意味着更多的線程會降低性能。 #include <thread> #include <functional> #include <nu
原创 批量創建線程
生成一批線程並等待它們完成 #include <thread> #include <functional> #include <algorithm> #include <vector> #include <iostream> v
原创 確定對象被使用前已被初始化
/* 有時候可能會用到static變量,如果將static變量定義成non-local的, 那麼我們無法保障在需要使用該變量的時候該變量已經進行被初始化了; 解決該問題的方式是將non-local的靜態變量定義到函數
原创 數據成員是reference或const時該如何賦值?
#include <string> #include <iostream> class Dog { public: // 成員是reference或const時必須在初始化列表中進行賦值 Dog(std::str
原创 Copy all parts of an object.
在實現Derived類的copy constructor和copy assignment的時候,不僅要copy derived類的成員,還要拷貝base類的成員。 #include <string> #include <iost
原创 copy constructor 和 copy assignment很好區分
#include <iostream> #include <string> class Air { public: Air(std::string name="") :m_name(name) { std
原创 function pointer in C
函數指針數組: #include <stdio.h> int add(int a, int b) { return a + b; } int plus(int a, int b) { return a - b; } in
原创 cv::parallel_for_
#include <iostream> #include <string> #include <vector> #include <opencv2/core/internal.hpp> class Loop_Invoker :
原创 Handle assignment to self in operator=
智能指針 版本一, swap and copy #include <string> #include <memory> #include <iostream> class Bitmap { public: Bitmap(
原创 TensorFlow Micellany
當數據是一個數的時候,可以不管shape進行比較數據的大小,例如,下面的例子b和c的shape不同,但if條件語句的句子會被執行。 with tf.Session() as sess: a = tf.constant(
原创 vtable什麼時候會被創建?
我們寫了一個base類,並有(很多)derived類繼承它,同時每個類都有很多成員函數,但是如果類中是沒有虛函數的,那麼編譯器是不會浪費空間去創建vtable的。 看如下代碼: #include <iostream> class