OVERLAPPED

un }; };

結構類型聲明

OVERLAPPED結構類型聲明如下:
typedef struct _OVERLAPPED {
ULONG_PTR Internal; //作業系統保留,指出一個和系統相關的狀態
ULONG_PTR InternalHigh; //指出傳送或接收的數據長度
union {
struct {
DWORD Offset; //檔案傳送的開始位置
DWORD OffsetHigh; //檔案傳送的位元組偏移量的高位字
};
PVOID Pointer; //指針,指向檔案傳送位置
};
HANDLE hEvent; //指定一個I/O操作完成後觸發的事件
} OVERLAPPED, *LPOVERLAPPED;

OVERLAPPED結構的作用

I/O設備處理必然讓主程式停下來乾等I/O的完成,解決這個問題,可以使用OVERLAPPED。
OVERLAPPED I/O是WIN32的一項技術, 你可以要求作業系統為你傳送數據,並且在傳送完畢時通知你。這項技術使你的程式在I/O進行過程中仍然能夠繼續處理事務。事實上,作業系統內部正是以執行緒來I/O完成OVERLAPPED I/O。你可以獲得執行緒的所有利益,而不需付出什麼痛苦的代價。也就是說,OVERLAPPED主要是設定異步I/O操作,異步I/O操作是指應用程式可以在後台讀或者寫數據,而在前台做其他事情。
Allen denver在他的《Serial Communication in Win32》中是這樣解釋OVERLAPPED I/O的:我個人認為還是比較準確的
Overlapped I/O is not as straightforward as nonoverlapped I/O, but allows more flexibility and efficiency. A port open for overlapped operations allows multiple threads to do I/O operations at the same time and perform other work while the operations are pending. Furthermore, the behavior of overlapped operations allows a single thread to issue many different requests and do work in the background while the operations are pending.

相關詞條

相關搜尋

熱門詞條

聯絡我們