• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            MyMSDN

            MyMSDN記錄開發(fā)新知道

            計時器代碼片段

            這不是一個面向?qū)ο蟮拇a庫,它的存在僅僅只是為了說明幾個函數(shù)調(diào)用,如果要在您的工程中應(yīng)用相關(guān)內(nèi)容,請自行構(gòu)建(這應(yīng)該不難),或者看看我推薦的文檔。

            // ProcessAffinity.cpp : 定義控制臺應(yīng)用程序的入口點。
            //
            
            #include "stdafx.h"
            #include <windows.h>
            #include <iostream>
            #include <vector>
            
            using namespace std;
            void DisplayFrequency(ostream &out, LARGE_INTEGER &freq);
            
            struct TimeSpan
            {
                LARGE_INTEGER *Frequency;
                LARGE_INTEGER StartCounter;
                LARGE_INTEGER StopCounter;
                BOOL HAS_ERROR;
                double CalTimeSpan(){
                    return (StopCounter.QuadPart - StartCounter.QuadPart)/Frequency->QuadPart;
                }
            };
            
            int _tmain(int argc, _TCHAR* argv[])
            {
                HANDLE CurrentProcessHandle;
                DWORD ProcessAffinityMask, SystemAffinityMask, AllowProcessAffinity;
            
                CurrentProcessHandle = GetCurrentProcess();
            
                //GetCurrentProcess返回一個常量,代表當(dāng)前的進程句柄
                cout<<CurrentProcessHandle<<endl;
                cout<<(HANDLE)-1<<endl;
                cout<<(void*)-1<<endl;
                cout<<(void*)0xffffffff<<endl;
            
                cout<<"-----------------------------"<<endl;
            
                if(GetProcessAffinityMask(CurrentProcessHandle, &ProcessAffinityMask, &SystemAffinityMask))
                {
                    cout<<ProcessAffinityMask<<endl;    //0x0001
                    cout<<SystemAffinityMask<<endl;        //0x0001
                
                    AllowProcessAffinity = ProcessAffinityMask & SystemAffinityMask;
                    cout<<AllowProcessAffinity<<endl;
                }
            
                LARGE_INTEGER Freq;
                typedef vector<LARGE_INTEGER> FreqVec_type;
                FreqVec_type FreqVec;
                
                while(FreqVec.size() != 5)
                {
                    if(QueryPerformanceFrequency(&Freq))
                    {
                        DisplayFrequency(cout, Freq);
                        FreqVec.push_back(Freq);
                    }
                    Sleep(1000);
                }
            
                for(FreqVec_type::iterator iter = FreqVec.begin(); iter!=FreqVec.end(); ++iter)
                {
                    DisplayFrequency(cout, *iter);
                }
            
                cout<<"---------------------"<<endl;
            
                //calculate the timeSpan;
                TimeSpan ts;
                int sleepTime(3123);
            
                ts.Frequency = &Freq;
            
                if(QueryPerformanceCounter(&ts.StartCounter))
                {
                    ts.HAS_ERROR = false;
                    Sleep(sleepTime);
                }
                if(!ts.HAS_ERROR)
                {
                    QueryPerformanceCounter(&ts.StopCounter);
                }
                
                cout<<ts.CalTimeSpan()<<endl;
                cout<<(ts.StopCounter.QuadPart-ts.StartCounter.QuadPart)/sleepTime<<endl;
            
                return 0;
            }
            
            void DisplayFrequency(ostream &out, LARGE_INTEGER &freq)
            {
                out<<"start display!"<<endl;
                out<<freq.HighPart<<endl;
                out<<freq.LowPart<<endl;
                out<<freq.QuadPart<<endl;
                out<<"end display!"<<endl;
            }
            
            

            推薦文檔:《使用增強的計時器測量代碼段》(下載可適合打印,已排版,閱讀該文檔需要使用Microsoft Word 2007或相關(guān)閱讀器(后綴docx),如您需要pdf文檔,可以給我留言,我會將它發(fā)給你,在CSDN的下載中,您可能需要注冊成為相關(guān)網(wǎng)站的會員,或者使用積分,如果您覺得麻煩,可以直接向我索取!點此獲取!

            posted on 2009-02-19 01:49 volnet 閱讀(653) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            特殊功能
             
            热久久视久久精品18| 丁香狠狠色婷婷久久综合| 成人妇女免费播放久久久| 午夜天堂av天堂久久久| 一本色道久久HEZYO无码| 久久er热视频在这里精品| 久久er国产精品免费观看8| 久久久人妻精品无码一区| 日产精品久久久一区二区| 久久久久18| 91精品国产乱码久久久久久| 久久夜色精品国产亚洲| 久久精品一区二区三区AV| 九九99精品久久久久久| 99久久成人18免费网站| 久久精品麻豆日日躁夜夜躁| 久久精品亚洲精品国产欧美| 久久婷婷五月综合97色一本一本| 久久国产高潮流白浆免费观看| 国产精品伦理久久久久久| 久久99国产乱子伦精品免费| 亚洲国产精品久久久久| 亚洲AV无码久久精品成人| 91精品国产91久久久久久| 亚洲中文久久精品无码| 久久人妻少妇嫩草AV无码蜜桃 | 亚洲精品高清久久| 久久久国产打桩机| 四虎国产精品免费久久| 久久久精品人妻无码专区不卡| 潮喷大喷水系列无码久久精品| 四虎国产精品成人免费久久| 91超碰碰碰碰久久久久久综合| 久久久噜噜噜www成人网| 久久er99热精品一区二区| 久久久精品人妻无码专区不卡| 久久www免费人成精品香蕉| 久久精品国产99国产精品澳门| 伊人色综合久久| 久久美女网站免费| 伊人久久大香线蕉精品|