這不是一個(gè)面向?qū)ο蟮拇a庫,它的存在僅僅只是為了說明幾個(gè)函數(shù)調(diào)用,如果要在您的工程中應(yīng)用相關(guān)內(nèi)容,請自行構(gòu)建(這應(yīng)該不難),或者看看我推薦的文檔。
// ProcessAffinity.cpp : 定義控制臺應(yīng)用程序的入口點(diǎn)。
//
#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返回一個(gè)常量,代表當(dāng)前的進(jìn)程句柄
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;
}
推薦文檔:《使用增強(qiáng)的計(jì)時(shí)器測量代碼段》(下載可適合打印,已排版,閱讀該文檔需要使用Microsoft Word 2007或相關(guān)閱讀器(后綴docx),如您需要pdf文檔,可以給我留言,我會將它發(fā)給你,在CSDN的下載中,您可能需要注冊成為相關(guān)網(wǎng)站的會員,或者使用積分,如果您覺得麻煩,可以直接向我索取!點(diǎn)此獲取!)