Absolute Delays in C/C++ under win 98/xp/nt

Status
Not open for further replies.

visweswara

Newbie level 3
Joined
Apr 13, 2005
Messages
3
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,296
How to program to generate real-time delay of microsecond or millisecond using c/c++ under windows 98/xp/nt ?
 

what you need is

void delaySeconds( float seconds )
{
__int64 timeEllapsed;
__int64 timeStart;
__int64 timeDelta;

QueryPerformanceFrequency( (LARGE_INTEGER*)(&timeDelta ) );
QueryPerformanceCounter ( (LARGE_INTEGER*)(&timeStart ) );

__int64 timeToWait = (double)timeDelta * (double)seconds;

timeEllapsed = timeStart;

while( ( timeEllapsed - timeStart ) < timeToWait )
{
QueryPerformanceCounter( (LARGE_INTEGER*)(&timeEllapsed ) );

};
}

void delayMiliSeconds( float miliseconds )
{
__int64 timeEllapsed;
__int64 timeStart;
__int64 timeDelta;

QueryPerformanceFrequency( (LARGE_INTEGER*)(&timeDelta ) );

__int64 timeToWait = (double)timeDelta * (double)miliseconds/1000.0f;

QueryPerformanceCounter ( (LARGE_INTEGER*)(&timeStart ) );

timeEllapsed = timeStart;

while( ( timeEllapsed - timeStart ) < timeToWait )
{
QueryPerformanceCounter( (LARGE_INTEGER*)(&timeEllapsed ) );

};
}

void delayMicroSeconds( float microseconds )
{
__int64 timeEllapsed;
__int64 timeStart;
__int64 timeDelta;

QueryPerformanceFrequency( (LARGE_INTEGER*)(&timeDelta ) );

__int64 timeToWait = (double)timeDelta * (double)microseconds / 1000000.0f;

QueryPerformanceCounter ( (LARGE_INTEGER*)(&timeStart ) );

timeEllapsed = timeStart;

while( ( timeEllapsed - timeStart ) < timeToWait )
{
QueryPerformanceCounter( (LARGE_INTEGER*)(&timeEllapsed ) );

};
}
 

    visweswara

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…