原创 信號量:Semaphore:Release
using System; using System.Threading; public class Example { private s
原创 銀行賬戶鎖:Transaction:Lock(this)
using System;using System.Threading; namespace ThreadSimple{ internal class Account { int balance;
原创 重載操作符:Array:Overload Operator
#include "stdafx.h"#include <iostream>#include <stdlib.h>using namespace std;class Array{private : int size; int low; i
原创 構造堆棧:Private List Can Be Converted To Stacklist
// stack.cpp : Defines the entry point for the console application.// #include "stdafx.h"#include<iostream>using namesp
原创 送花之手動重設:Send Flower:Set A Signal of Ending
using System; using System.Threading; public class TestMain{ private static ManualResetEvent ent = new ManualResetE
原创 送花同步:AutoResetEvent=ManualResetEvent(Set+Reset)
using System; using System.Threading; public class TestMain{ private static AutoResetEvent ent = new AutoResetEvent(
原创 讀寫同步:AutoResetEvent:ReadThread After WriteThread
using System;using System.Threading; namespace AutoResetEvent_Examples{ class MyMainClass { const int numI
原创 inline是個申請,編譯器可以忽略
inline void f(){...} void (*pf)()=f; //pf指向f ... f(); //這個調用被inline pf();//這個或許不被inline,因爲是通過函數指針達成
原创 Dynamic_cast的效率問題
dynamic_cast的作用:在derived class身上執行derived class 執行函數,手頭只有指向base的pointer或reference. 方案一: class Window{...}; class Specia
原创 遍歷目錄
#include "stdafx.h"#include "windows.h"#include "string.h"#include "time.h" //clock() #define MAX 1000 int level = 0;i
原创 讓接口容易被正確使用,不易被誤用
Make interfaces easy to use correctly and hard to use incorrectly. 爲表現日期的class設計構造函數: class Date{ public : Date(int mon
原创 智能指針
今天開始寫c++ effective的讀書筆記。 以對象管理資源需要pointer-like object,即智能指針。 #include "stdafx.h"#include "iostream"#include "memory" us
原创 FTP客戶端:上傳需要關閉Socket
#include "stdafx.h" #include <WinSock2.h> #include <fstream> #include "iostream" using namespace s
原创 重載String:Overload String
#include "stdafx.h"#include <iostream>#include <stdlib.h>using namespace std;class String{private: char* ch; int size;p