Re: Real time clock with millisecond resolution <newb>
"Hunter" <Igal.Hunter@gmail.com> wrote in message
news:1188220541.699045.103270@o80g2000hse.googlegroups.com...
Hi all,
Please forgive me for my newbie question. It's just that I've run out
of options, so I'm posting my question here.
What I need is to implement a time-stamping mechanism, and I need the
time to be in millisecond resolution. I tried my best with the
standard ansi C functions, but the best I could get was a real-time
clock with seconds.
However, I was given a good advice, to try and look for something
system-specific that would provide me with a calendar-time clock with
millisecond resolution and precision.
If anyone knows how I can access calendar time with a resolution as
high as millisecond, and similar precision, I'll appreciate the help.
Please write your answer as simple as possible, as I'm not a
professional programmer, so my C skills are a limited.
My system is a Desktop running Win2000, I have a Visual C++ 6.0
I implemented a Windows version of gettimeofday. What I did was to get the
current system time (to the nearest second) and also call
QueryPerformanceCounter. Then I arbitrarily choose that the milliseconds
are zero at that time. Later, calling QueryPerformanceCounter again gives
you very high resolution elapsed time, which you can add to your original
system time to get a high resolution calendar time.
The only drawback with that is that the extra resolution isn't shared
between processes. But for most cases, like if you just need extra
precision in your debug log, it's great. Computer time can't be expected to
be synchronized to any external source with better than +/- 1 second anyway.
Thank you very much.