189 8069 5689

c语言重复调用函数太慢 c语言重复执行命令

C语言main调用函数a并运行5秒然后切换函数b运行5秒,以此重复

两种情况:

创新互联主要从事网站建设、成都网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务解放,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575

a函数或者b函数或者a、b函数在5秒内执行不完,这种情况,最好是使用多线程或者多进程;创建2个线程或者2个进程,让a函数在一个进程(线程)执行,b函数在另外一个进程(线程)执行,5秒后调度另一个进程(线程)执行;

a,b在5秒内都能执行完成,那就在一个循环里面:先获取执行前的机器时间,加5秒,执行完函数,再次获取机器时间,和原机器时间加5秒,作对比,大于或者等于了,就执行另外一个函数。

c语言,循环,函数调用,循环不终止,一直在跑

#includestdio.h

#includemalloc.h

int swap (int x)

{

if(x%4==1x%5==3x%7==4)

return 1;

else return 0;

}

int main(void)

{

int i,s;

for(i=200; 200=i i=500;i++)

{

s=swap(i);

if(s==1)

printf("output:%d\n",i);

}

return 0;

}

C语言 程序多次运行后,速度变慢的问题!

My guess would be you are adding while loops when you press B.

From what I understand, you are not using any heap memory, cuz there is no new or malloc being called.

The size of a stack is usually 1M under Visual Studio by default, it canbe changed somewhere in the project property, and it is where you declare variables e.g

int x[10]; char c;

If you declare int x[1024*1024], which is 4MB under a 32bit system, it runs out the stack memory and results in an error, e.g. "Program stops working" and stuff.

If you want to prevent this from happening, you should actually use new or malloc cuz it gives you sufficient space on both physic memory and virtual memory on which you would never run out.

Above is just a brief explanation about stack and heap.

Can you please upload the code, especially for the part that responds to "B", otherwise it would be purely guessing and wouldn't be helpful at all.

C语言在一个函数中多次调用另一个函数问题

要么你短点调试,要么你代码贴上来,要么你分析一下你的代码,跟着程序分析一下过程,要么就是程序运行太快调用了你没看出来,要么就是你的程序还没有运行到第二次调用就已经结束了。。。


文章题目:c语言重复调用函数太慢 c语言重复执行命令
文章来源:http://cdxtjz.com/article/dosepgc.html

其他资讯