Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GetMessage vs. PeekMessage: which is more effecient?

239 views
Skip to first unread message

tsc

unread,
Feb 4, 1997, 3:00:00 AM2/4/97
to

I was told today by a coworker that a Peekmessage loop is more
effecient than a Getmesage loop. I would hae thought that as long as
the message queue was empty, these two APIs would be equally fast or
slow. Which is right? Is PeekMessage more effecient or better in some
other way for polling the message queue than GetMessage, especially if
you only expect occasional messages? Thanks.


Ken Litwak

David Lowndes

unread,
Feb 5, 1997, 3:00:00 AM2/5/97
to

Ken,

They are used differently. GetMessage only returns when there is a
message in your applications message queue. PeekMessage will also
return when your mesage queue is empty - so letting you perform other
tasks in your message loop (idle time processing).

Dave
----
Address is altered to discourage junk mail.
Remove ".---" for the real address.

Kenneth Litwak

unread,
Feb 5, 1997, 3:00:00 AM2/5/97
to David Lowndes

>They are used differently. GetMessage only returns when there is a
>message in your applications message queue. PeekMessage will also
>return when your mesage queue is empty - so letting you perform other
>tasks in your message loop (idle time processing).
>
>Dave

Understood, Dave, but the question I really want to resolve is
whether it's actually faster or somehow better, if you don't need to do
anything until the next message, to use PeekMessage instead of
GetMessage. I haven't seen any samples that use PeekMessage in the main
message loop nor do any of the authors I have, like Petzold or Richter,
say PeekMessage is better. That's the point. Thanks.

Ken

David Lowndes

unread,
Feb 6, 1997, 3:00:00 AM2/6/97
to

> Understood, Dave, but the question I really want to resolve is
>whether it's actually faster or somehow better, if you don't need to do
>anything until the next message, to use PeekMessage instead of
>GetMessage. I haven't seen any samples that use PeekMessage in the main
>message loop nor do any of the authors I have, like Petzold or Richter,
>say PeekMessage is better. That's the point. Thanks.

Ken,

If you application doesn't need to use PeekMessage to do idle
processing, then GetMessage will be more efficient on the system as it
never returns to your application to waste time in your message loop
when there aren't any messages pending in your message queue.

Seems a reasonable argument to me.

0 new messages