嵌入式系统中的C ++使用 [英] C++ usage in embedded systems
本文介绍了嵌入式系统中的C ++使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在嵌入式系统中应避免使用C ++的哪些功能?
请按照以下原因对答案进行分类:
- 内存使用
- 代码大小
- 速度
- / li>
编辑:让我们使用一个带64k RAM的ARM7TDMI作为目标来控制答案的范围。
解决方案
RTTI和异常处理:
- 增加代码大小
- 降低效果
- 通常可以用更便宜的机制或更好的软件设计取代。
模板:
- 如果代码大小是一个问题。如果你的目标CPU没有或只有一个非常微小的指令缓存,它可能会降低性能。 (如果不小心使用,模板往往会膨胀代码)。 Otoh聪明的元编程也可以减小代码大小。对他没有明确的答案。
虚函数和继承:
$ b
- 这些对我很好。我写几乎所有的我的嵌入式代码在C.这不阻止我使用函数指针表来模仿虚拟函数。他们从来没有成为一个性能问题。
What features of C++ should be avoided in embedded systems?
Please classify the answer by reason such as:
- memory usage
- code size
- speed
- portability
EDIT: Lets' use an ARM7TDMI with 64k ram as a target to control the scope of the answers.
解决方案
RTTI and Exception Handling:
- Increases code-size
- Decreases performance
- Can often be replaced by cheaper mechanisms or a better software-design.
Templates:
- be careful with them if code-size is an issue. If your target CPU has no or only a very tiny ínstruction cache it may reduce the performance as well. (templates tend to bloat code if used without care). Otoh clever meta-programming can decrease the code-size as well. There is no clear cut answer on his.
Virtual functions and inheritance:
- These are fine for me. I write almost all of my embedded code in C. That does not stop me from using function-pointer tables to mimic virtual functions. They never became a peformance problem.
这篇关于嵌入式系统中的C ++使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文