实时编程 [英] real-time programming

查看:68
本文介绍了实时编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我们在嵌入式Linux系统上创建一个实时程序。

程序将运行几秒钟


i想知道创建全局变量是否更好或者在main中创建变量并将其传递给函数?


谢谢

hi

we create a real-time program on a embedded linux system.
the program will run a few time by second

i would like to know if it''s better to create global variable or create
the variable in the main and pass it to the function?

thanks

推荐答案

ma ******* @ yahoo.com 写道:
ma*******@yahoo.com wrote:
我们在嵌入式Linux系统上创建一个实时程序。
该程序每秒运行几次。

我想知道创建全局变量
或在main中创建变量并将其传递给函数?
We create a real-time program on a embedded linux system.
The program will run a few times each second.

I would like to know if it''s better to create global a variable
or create the variable in the main and pass it to the function?




在调用函数[main]中创建局部变量总是更好



并传递它的功能。



It''s always better
to create a local variable in the calling function [main]
and pass it the function.


ok但是这会产生很多操作堆栈

ok but that will generate a lot of operation on the stack


" E. Robert Tisdale <,E ************** @ jpl.nasa.gov>。写道:
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> writes:
ma*******@yahoo.com 写道:
ma*******@yahoo.com wrote:
我们在嵌入式Linux系统上创建一个实时程序。
程序将每秒运行几次。
我想知道它是否'最好创建全局变量
或在main中创建变量并将其传递给函数?
We create a real-time program on a embedded linux system.
The program will run a few times each second.
I would like to know if it''s better to create global a variable
or create the variable in the main and pass it to the function?



创建它总是更好
调用函数[main]中的局部变量
并将其传递给函数。



It''s always better
to create a local variable in the calling function [main]
and pass it the function.




总是?


stdin,stdout和stderr应该是局部变量吗?


OP:你的意思是什么?更好?如果你指的是

性能,那么C语言没有说明使用local或

全局变量会导致更快的代码;差异,如果有的话,

不大可能。使用本地人通常可以获得更清晰的代码和更易维护的代码。另一方面,如果你有很多

的数据对你的整个程序来说真的是全局的,那么人为地将它变成局部的b / b $ b $参数可能会使你的

代码可维护性较差。


如果这是一个实时程序非常重要的事实,那你就是
可能会在comp.realtime或comp.os.linux.embedded中获得更好的信息。


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< * GT; < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



Always?

Should stdin, stdout, and stderr be local variables?

To the OP: what do you mean by "better"? If you''re referring to
performance, the C language says nothing about whether using local or
global variables results in faster code; the difference, if any, is
not likely to be significant. Using locals often results in cleaner
and more maintainable code. On the other hand, if you have a lot of
data that really is global to your entire program, artificially making
it local and passing it around as parameters will probably make your
code less maintainable.

If the fact that it''s a real-time program is really relevant, you
might get better information in comp.realtime or comp.os.linux.embedded.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于实时编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆