处理5000种不同的功能 - C中的优化方式 [英] Handling 5000 different functionalities - Optimised way in C

查看:64
本文介绍了处理5000种不同的功能 - C中的优化方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一块Coldfire与另一方的PC通讯。


PC将通过以下方式发送TCP / IP大约5000个不同的命令

识别号码只需1分钟到董事会的
(考虑1到5000)。


董事会在Coldfire上有Ucos和8MB闪存。

董事会将解析id并按照规范执行不同的操作

并将输出发送回通过TCP / IP的PC。


我认为'if-else''不是一个好的选择,因为它吃掉堆栈和''切换

case''也不是一个好选项,因为它内部只使用'if-else'。


有没有其他优化的方法在C中实现它?


thx of the advans,

Karthik Balaguru

Hi,

I have a Board of Coldfire communicating with a PC on the other side.

The PC will be sending via TCP/IP some 5000 different command
identification numbers only
( consider 1 to 5000 ) at 1 minute interval to the board.

The board has Ucos on Coldfire and 8MB flash .
The board will parse the id and carry out the different operations as
per the specification and send the output back to the PC via TCP/IP.

I think ''if-else'' is not a good option as it eats up stack and ''switch
case '' is also not a good option as it internally uses ''if-else'' only.

Is there any other optimised way to implement this in C ?

Tonnes of Thx in advans,
Karthik Balaguru

推荐答案

karthikbg写道:
karthikbg wrote:




我有一个Coldfire板与另一端的PC通信。


PC将通过TCP / IP发送大约5000个不同的命令

识别号码只需$ 1 $ b(考虑1到5000),每隔1分钟就可以登机。


董事会在Coldfire上安装Ucos,8MB闪存。

电路板将解析id并按照规范执行不同的操作

,并通过TCP / IP将输出发送回PC。


我认为'if-else''不是一个好选择,因为它吃掉堆栈和''切换

case''也不是一个好选择,因为它内部只使用''if-else''。


有没有其他优化的方法在C中实现这个?
Hi,

I have a Board of Coldfire communicating with a PC on the other side.

The PC will be sending via TCP/IP some 5000 different command
identification numbers only
( consider 1 to 5000 ) at 1 minute interval to the board.

The board has Ucos on Coldfire and 8MB flash .
The board will parse the id and carry out the different operations as
per the specification and send the output back to the PC via TCP/IP.

I think ''if-else'' is not a good option as it eats up stack and ''switch
case '' is also not a good option as it internally uses ''if-else'' only.

Is there any other optimised way to implement this in C ?



C没有提及代码生成和优化的细节。什么

让你说开关不够好?你真的尝试过吗?

是什么让你断定交换机在内部使用if?你有没有实际检查发出的汇编代码?
你尝试过一个简单的循环吗?

C says nothing about details of code generation and optimisation. What
makes you say that switch isn''t good enough? Did you actually try it?
What makes you conclude that switch uses if else internally? Did you
actually inspect the assembly code emitted? Did you try a simple loop?


>

thx吨的优惠,

Karthik Balaguru
>
Tonnes of Thx in advans,
Karthik Balaguru




santosh写道:

santosh wrote:

karthikbg写道:
karthikbg wrote:




我有一个Coldfire Board与另一方的PC通信。


PC将通过TCP / IP发送大约5000个不同的命令

识别号码

(考虑1到5000)1分钟董事会间隔。


董事会在Coldfire和8MB闪存上都有Ucos。

董事会将解析id并执行不同的操作/>每个规格的
并通过TCP / IP将输出发送回PC。


我认为'if-else''不是一个好的选择,因为它吃掉堆栈和''切换

case''也不是ag ood选项,因为它内部只使用''if-else''。


有没有其他优化的方法在C中实现它?
Hi,

I have a Board of Coldfire communicating with a PC on the other side.

The PC will be sending via TCP/IP some 5000 different command
identification numbers only
( consider 1 to 5000 ) at 1 minute interval to the board.

The board has Ucos on Coldfire and 8MB flash .
The board will parse the id and carry out the different operations as
per the specification and send the output back to the PC via TCP/IP.

I think ''if-else'' is not a good option as it eats up stack and ''switch
case '' is also not a good option as it internally uses ''if-else'' only.

Is there any other optimised way to implement this in C ?



C没有提及代码生成和优化的细节。什么

让你说开关不够好?你真的尝试过吗?

是什么让你断定交换机在内部使用if?你有没有实际检查发出的汇编代码?
你尝试过一个简单的循环吗?


C says nothing about details of code generation and optimisation. What
makes you say that switch isn''t good enough? Did you actually try it?
What makes you conclude that switch uses if else internally? Did you
actually inspect the assembly code emitted? Did you try a simple loop?



thx of the advans,

Karthik Balaguru

Tonnes of Thx in advans,
Karthik Balaguru



我在寻找

方法的缺点时遇到了如下网上的内容

可以尝试实现5000种不同情况的处理。


UNIX下的cc编译器(Silicon Graphics,R3000处理器)生成


这样用汇编语言:

C PSEUDO ASSEMBLY

------------------------ ------------------------------

switch(j)LOAD j INTO register_1

{JUMP label_default(无条件)


案例1000:.... label_1000:

....(如果没有跳转到label_end

休息)

案例2000:.... label_2000:

....

c ase 500:.... label_500:

....

默认值:.... label_default:

BRANCH label_1000如果register_1 = =



BRANCH label_2000如果register_1 ==

2000

BRANCH label_500如果register_1 ==

500

.....

} label_end:

------------ --------------------------------------------


正如您所看到的案例声明最后是一系列的ifs,


所以,我相信案例声明最后是一系列''ifs''

如果这是错误的,请告诉我案例是怎样的。语句将实现

用C语言实现



所以,我正在寻找一种除了''切换之外的优化方法-case''。


Karthik Balaguru

I came across something as below in net while looking in for the
disadvantages of methods
that can be tried to implement the handling of 5000 different cases.

The cc compiler under UNIX (Silicon Graphics, R3000 processor) produces

something like this in the assembly language:
C PSEUDO ASSEMBLY
------------------------------------------------------
switch(j) LOAD j INTO register_1
{ JUMP label_default (unconditionally)

case 1000: .... label_1000:
.... (no jump to label_end if no
break)
case 2000: .... label_2000:
....
case 500: .... label_500:
....
default: .... label_default:
BRANCH label_1000 if register_1 ==
1000
BRANCH label_2000 if register_1 ==
2000
BRANCH label_500 if register_1 ==
500
.....
} label_end:
--------------------------------------------------------

As you see the "case" statement finally is a serie of "ifs",

So, i believe that "case" statment finally is a series of ''ifs''
If that is wrong, Kindly tell me how the "case" statement would have
been implemented
in C language.

So, I am looking an optmised method other than ''switch-case'' .

Karthik Balaguru


karthikbg写道:
karthikbg wrote:

santosh写道:
santosh wrote:

karthikbg写道:
karthikbg wrote:



我有一个Coldfire板与另一侧的PC通信。

>

PC将通过TCP / IP发送大约5000个不同的命令

仅限识别号码

(考虑1到5000),每隔1分钟一次。
Hi,
I have a Board of Coldfire communicating with a PC on the other side.
>
The PC will be sending via TCP/IP some 5000 different command
identification numbers only
( consider 1 to 5000 ) at 1 minute interval to the board.



< snip>

<snip>


我认为'if-else''不是一个好选择,因为它吃掉了堆栈和''开关

case''也不是一个好选择,因为它内部只使用''if-else''。

>

有没有其他优化的方法在C中实现这个?
I think ''if-else'' is not a good option as it eats up stack and ''switch
case '' is also not a good option as it internally uses ''if-else'' only.
>
Is there any other optimised way to implement this in C ?



C没有提及代码生成和优化的细节。什么

让你说开关不够好?你真的尝试过吗?

是什么让你断定交换机在内部使用if?你有没有实际检查发出的汇编代码?
你试过一个简单的循环吗?

C says nothing about details of code generation and optimisation. What
makes you say that switch isn''t good enough? Did you actually try it?
What makes you conclude that switch uses if else internally? Did you
actually inspect the assembly code emitted? Did you try a simple loop?



< snip>

<snip>


我在网上找到了以下内容,同时寻找方法
I came across something as below in net while looking in for the
disadvantages of methods

$ b的

缺点
$ b为什么不检查_your_编译器的输出而不是

在网上搜索?


< snip>

Why don''t you inspect the output of _your_ compiler rather than
searching around on the net?

<snip>


UNIX下的cc编译器(Silicon Graphics,R3000处理器)产生
The cc compiler under UNIX (Silicon Graphics, R3000 processor) produces



< snip>

<snip>


所以,我相信案例声明最后是一系列''ifs''

如果这是错误的,请告诉我案例是怎样的。语句将用C语言实现


So, i believe that "case" statment finally is a series of ''ifs''
If that is wrong, Kindly tell me how the "case" statement would have
been implemented in C language.



C标准没有提及代码生成。通常使用多个案例标签切换

语句实现为跳转

表。对于特定的实现,这可能是也可能不是。


此时,您将在特定于您的平台的组中询问或

编译器。尝试comp.programming,alt.lang.asm,comp.embedded和

comp.compilers。

The C standard says nothing about code generation. Typically switch
statements with more than a few case labels are implemented as jump
tables. This may or may not be true for a particular implementation.

At this point, you''ll have ask in a group specific to your platform or
compiler. Try also comp.programming, alt.lang.asm, comp.embedded and
comp.compilers.


这篇关于处理5000种不同的功能 - C中的优化方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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