加入比较短时间的Sleep()一般对时效性影响不大,但能极大地降低CPU占用。
- 比如,这里我们用coolfun::UI_suspend()等待按键函数的源码来举例:
#include<conio.h>
#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
cout << "<< 按任意键继续... ";
for (int i = 0; _kbhit() == 0;) //等待按键
{
switch (i++) //选择打印最后的一个字符,使之有动画效果
{
case 0:cout << "\b/"; break;
case 1:cout << "\b-"; break;
case 2:cout << "\b\\"; break;
case 3:
{
cout << "\b|";
i = 0;
}break;
}
//Sleep(100); //暂停100毫秒(1秒 = 1000毫秒)
}
}
- 效果:

- 但是它的CPU占用相当的高,一直了 8% 左右,而这还仅仅是一个简单的动画功能。

- 那接下来我们在循环内加一条Sleep():

- 然后再来看看它的CPU占用:

- 可以看到,显示的是CPU占用 0%,显然是因为占用太低了,所以才显示了 0%。
- 这句Sleep(100),暂停的100毫秒对用户来说基本没感觉,但却大幅度降低了CPU占用,而且动画效果甚至更舒服了:

site combien d urine en 24h correction presbytie lentilles maladie dГ©gГ©nГ©rative des muscles anatomie petit bassin operation de l urГЁtre svt terminale s gГ©nГ©tique anatomie de la racine des plantes philip stubbes anatomie of abuses yeux de deux couleurs diffГ©rentes buy generic lasix online
nolvadex Given the clinical significance of this we suggest to further review the value of ID interventions on PAB in a prospective study
Average lifetime manure production was estimated at 11, 1287, and 20, 300 lb animal for poultry, swine, and beef cattle, respectively 80 buy cialis online Moreover, functional studies indicate that decidual angiogenesis is mainly regulated by vascular endothelial growth factor A VEGF- A secreted from decidual stromal cells expressing PR; thus, greater expression of VEGF- A corresponds to high PR expression