Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I want to control a timing loop every millisecond using ‘C’. I don’t think I can use the time & difftime functions as they only return seconds as units of time. I thought about the clock function but that only has a resolution of 10 milliseconds.
Can anyone point me in the right direction here.
Thanks
Mark

Windows supports a High Resolution Timer. The following functions are used:
BOOL QueryPerformanceFrequency(
LARGE_INTEGER *lpFrequency);
// lpFrequency is address of current frequencyBOOL QueryPerformanceCounter(
LARGE_INTEGER *lpPerformanceCount);
// lpPerformanceCount is pointer to counter valueSomeone has written a class to encapsulate this:
The CPerfTimer timer class
http://www.codeproject.com/datetime/perftimer.aspIf you do not want to use the class you can at least look at it to get an idea of how to use the high resolution timer.
Note: thers is no guarantee that your hardware supports the high resolution timer. Use the return value of QueryPerformanceFrequency to find out.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |