MSG::time is later than timeGetTime

A

Adam

After noticing some timing descrepencies with events in my code, I
boiled the problem all the way down to my Windows Message Loop.

Basically, unless I'm doing something strange, I'm experiencing this
behaviour:-

MSG message;

while (PeekMessage(&message, _applicationWindow.Handle, 0, 0,
PM_REMOVE))
{
int timestamp = timeGetTime();
bool strange = message.time > timestamp; //strange == true!!!

TranslateMessage(&message);
DispatchMessage(&message);
}
The only rational conclusion I can draw is that MSG::time uses a
different timing mechanism then timeGetTime() and therefore is free to
produce differing results. Is this the case or am i missing something
fundamental?

NB: strange is only true every now and again, and it's quite often so
I'm pretty sure it isn't a wrap around issue.
 
J

Jonathan Lee

After noticing some timing descrepencies with events in my code, I
boiled the problem all the way down to my Windows Message Loop.

Basically, unless I'm doing something strange, I'm experiencing this
behaviour:-

The only rational conclusion I can draw is that MSG::time uses a
different timing mechanism then timeGetTime() and therefore is free to
produce differing results. Is this the case or am i missing something
fundamental?

a) I'd probably ask in a MS newsgroup since this doesn't pertain to
anything C++ language specific
b) Multithreading could be at play, if different threads use different
timers. Or different processors.
c) timeGetTime() returns a DWORD, not an int (I believe DWORD is
unsigned on Windows).

--Jonathan
 
J

James Kanze

After noticing some timing descrepencies with events in my code, I
boiled the problem all the way down to my Windows Message Loop.
Basically, unless I'm doing something strange, I'm experiencing this
behaviour:-
MSG message;
while (PeekMessage(&message, _applicationWindow.Handle, 0, 0,
PM_REMOVE))
{
int timestamp = timeGetTime();
bool strange = message.time > timestamp; //strange == true!!!

The only rational conclusion I can draw is that MSG::time uses
a different timing mechanism then timeGetTime() and therefore
is free to produce differing results. Is this the case or am
i missing something fundamental?

Where does MSG get its time from? The names above sound like
there might be messaging between systems, in which case the MSG
time function might return the time the message was sent, as
read from the message. Which was written on a different
machine, whose clock is maybe not synchronized with the one on
your machine.
NB: strange is only true every now and again, and it's quite
often so I'm pretty sure it isn't a wrap around issue.

Check whether it depends on where the message came from.
 
A

Adam

Where does MSG get its time from?  The names above sound like
there might be messaging between systems, in which case the MSG
time function might return the time the message was sent, as
read from the message.  Which was written on a different
machine, whose clock is maybe not synchronized with the one on
your machine.


Check whether it depends on where the message came from.

Sorry, yes it is a win32 message loop. And it is all on the same
machine.
 
A

Adam

a) I'd probably ask in a MS newsgroup since this doesn't pertain to
anything C++ language specific
b) Multithreading could be at play, if different threads use different
timers. Or different processors.
c) timeGetTime() returns a DWORD, not an int (I believe DWORD is
unsigned on Windows).

--Jonathan

Multithreading/processors is a good shout, although i'm not doing
anything funky just a vanilla windows message loop.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,516
Members
44,983
Latest member
BuyX10BoostKeto

Latest Threads

Top