Computing.Net > Forums > Programming > Timing loop using ‘C’

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Timing loop using ‘C’

Reply to Message Icon

Name: Mark
Date: May 17, 2003 at 12:40:42 Pacific
OS: Win 98
CPU/Ram: p300/128
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: egkenny
Date: May 17, 2003 at 17:46:11 Pacific
Reply:

Windows supports a High Resolution Timer. The following functions are used:

BOOL QueryPerformanceFrequency(
LARGE_INTEGER *lpFrequency);
// lpFrequency is address of current frequency

BOOL QueryPerformanceCounter(
LARGE_INTEGER *lpPerformanceCount);
// lpPerformanceCount is pointer to counter value

Someone has written a class to encapsulate this:

The CPerfTimer timer class
http://www.codeproject.com/datetime/perftimer.asp

If 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.


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Timing loop using ‘C’

Getting file date/time using C www.computing.net/answers/programming/getting-file-datetime-using-c/10056.html

CGI Text file on hd using c/c++/per www.computing.net/answers/programming/cgi-text-file-on-hd-using-ccper/11020.html

Packet Capturing/Sniffing using C www.computing.net/answers/programming/packet-capturingsniffing-using-c/2080.html