制作我自己的Sleep()函数 [英] Making my own Sleep() function
问题描述
你好
如何在不使用while()和比较时间的情况下制作自己的睡眠功能?
我试图找到有用的东西谷歌,但我找不到任何有用的东西。
----
Nazwa
你好
如何在不使用while()和比较时间的情况下创建自己的Sleep功能?
我试图在谷歌上找到有用的东西,但我找不到任何有用的东西。
----
Nazwa
只需用参数调用延迟函数。
通过递减参数使函数递归。
将退出状态作为参数值给出为零。
对于Ex:
展开 | 选择 | Wrap | 行号
请不要这样做:
//延迟功能
无效延迟(int i)
{
if(i == 0)
返回;
延迟(i-10); //将减量定为1或10或100为方便
}
delay()函数以递归方式调用自身。当堆栈内存耗尽时,这将导致崩溃。
使用3.8GHZ处理器,您将需要一个非常大的循环来延迟甚至少量。
首先使用操作系统休眠功能有什么问题?
只需拨打延迟带参数的函数。
通过递减参数使函数递归。
将退出状态作为参数值给出为零。
例如:
展开 | 选择 | Wrap | 行数的BER 跨度>
Hello
How can I make my own Sleep function, without using while() and comparing time passed?
I tried to find something useful on google, but I wasn''t able to find anything useful.
----
Nazwa解决方案Hello
How can I make my own Sleep function, without using while() and comparing time passed?
I tried to find something useful on google, but I wasn''t able to find anything useful.
----
NazwaJust Call a delay function with a parameter.
make the function recursive by decrementing the parameter.
Give exit status as parameter value as Zero to come out.
For Ex:
Expand|Select|Wrap|Line Numbers
Please don''t do this:
//Delay Function
void delay(int i)
{
if (i == 0)
return;
delay(i-10); // give the decrement as 1 or 10 or 100 as convenient
}The delay() function recursively calls itself. This will lead to a crash when the stack memory is exhausted.
With a 3.8GHZ processor, you will need a very big loop indeed to delay even a small amount.
What is wrong with using the OS sleep function in the first place??
Just Call a delay function with a parameter.
make the function recursive by decrementing the parameter.
Give exit status as parameter value as Zero to come out.
For Ex:
Expand|Select|Wrap|Line Numbers
这篇关于制作我自己的Sleep()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文登录 关闭
扫码关注1秒登录发送“验证码”获取 | 15天全站免登陆