在嵌入式环境中使用C ++ [英] Using C++ in an embedded environment

查看:153
本文介绍了在嵌入式环境中使用C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我和一个同事进行了一个非常有趣的对话,其中一个主题让我思考和今天晚上googling。在嵌入式环境中使用C ++(而不是C)。环顾四周,似乎有一些不错的交易 C ++提供,但其他 Meyers 显然支持它。所以,我想知道谁能够阐明这个话题,以及社群的一般共识。

Today I got into a very interesting conversation with a coworker, of which one subject got me thinking and googling this evening. Using C++ (as opposed to C) in an embedded environment. Looking around, there seems to be some good trades for and against the features C++ provides, but others Meyers clearly support it. So, I was wondering who would be able to shed some light on this topic and what the general consensus of the community was.

推荐答案

这取决于您的嵌入式系统的特定性质和使用的C ++的功能。语言本身不一定会产生比C更大的代码。

It sort of depends on the particular nature of your embedded system and which features of C++ you use. The language itself doesn't necessarily generate bulkier code than C.

例如,如果内存是你最严格的约束,你可以使用C ++像C with classes - 也就是说,只使用直接成员函数,禁用RTTI,并且没有任何虚拟函数或模板。这将适合在几乎相同的空间作为等价的C代码,因为你没有类型信息,vtables或冗余的功能,杂乱的东西。

For example, if memory is your tightest constraint, you can just use C++ like "C with classes" -- that is, only using direct member functions, disabling RTTI, and not having any virtual functions or templates. That will fit in pretty much the same space as the equivalent C code, since you've no type information, vtables, or redundant functions to clutter things up.

我发现模板是内存非常紧张时避免的最大的事情,因为每个模板函数都有一个副本,可以迅速膨胀代码段。

I've found that templates are the biggest thing to avoid when memory is really tight, since you get one copy of each template function for each type it's specialized on, and that can rapidly bloat code segment.

在控制台视频游戏行业(这是嵌入式世界的一个强大的末端)C ++是王。我们的约束是对存储器(当前生成512mb)和实时性能的硬限制。通常使用虚拟函数和模板,但不是异常,因为它们使堆栈膨胀并且太昂贵。事实上,一个主要制造商的编译器甚至根本不支持异常。

In the console video games industry (which is sort of the beefy end of the embedded world) C++ is king. Our constraints are hard limits on memory (512mb on current generation) and realtime performance. Generally virtual functions and templates are used, but not exceptions, since they bloat the stack and are too perf-costly. In fact, one major manufacturer's compiler doesn't even support exceptions at all.

这篇关于在嵌入式环境中使用C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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