Message polling for Windows

Source: Internet
Author: User
A problem I saw on the Internet makes sense:
Q: Windows uses the message polling mechanism.ProgramIt will receive messages continuously until the end of the cycle, isn't it very resource-consuming? If I write a C ++ program and use a loop to constantly update the display time, the CPU usage will be very high, then what method does Windows use to make those message polling programs occupy very little resources?
A:
In a message loop, the most commonly used functions are getmessage () and peekmessage (). When the message queue is empty, the getmessage () function does not return a time slice, the thread does not occupy CPU resources. The peekmessage function returns immediately even if the message queue is empty, rather than blocking. The message loop does not occupy a lot of CPU resources because getmessage does not return when the message queue is empty. At this time, the operating system switches away from the thread until the thread receives the message.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.