嵌入式C ++:使用STL还是不行? [英] Embedded C++ : to use STL or not?

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

问题描述

我一直是一个嵌入式软件工程师,但通常在OSI堆栈的第3层或第2层。我不是一个硬件的家伙。我通常总是做电信产品,通常是手/手机,这通常意味着像ARM 7处理器。

I have always been an embedded software engineer, but usually at Layer 3 or 2 of the OSI stack. I am not really a hardware guy. I have generally always done telecoms products, usually hand/cell-phones, which generally means something like an ARM 7 processor.

现在我发现自己在更通用的嵌入式世界,在一个小的初创公司,我可能会移动到不那么强大的处理器(有主观的一点) - 我不能预测哪个。

Now I find myself in a more generic embedded world, in a small start-up, where I might move to "not so powerful" processors (there's the subjective bit) - I cannot predict which.

一点关于在嵌入式系统中使用C ++的讨论,没有明确的答案。有一些关于可移植性的小担心,以及一些关于代码大小或运行时的担心,但我有两个主要问题:

1 - 异常处理;我仍然不确定是否使用它(请参阅 http://stackoverflow.com) / questions / 2226227 / embeeded-c-to-use-exceptions-or-not

2 - 我强烈不喜欢嵌入式系统中的动态内存分配,因为它可能引入的问题。我通常有一个缓冲池,它在编译时静态分配,并且只提供固定大小的缓冲区(如果没有缓冲区,系统复位)。当然,STL做了很多动态分配。

I have read quite a bit about debate about using STL in C++ in embedded systems and there is no clear cut answer. There are some small worries about portability, and a few about code size or run-time, but I have two major concerns:
1 - exception handling; I am still not sure whether to use it (see http://stackoverflow.com/questions/2226227/embeeded-c-to-use-exceptions-or-not)
2 - I strongly dislike dynamic memory allocation in embedded systems, because of the problems it can introduce. I generally have a buffer pool which is statically allocated at compile time and which serves up only fixed size buffers (if no buffers, system reset). The STL, of course, does a lot of dynamic allocation.

现在我必须决定是使用还是放弃STL - 对于整个公司,永远(它会进入一些非常核心的s / w)。

Now I have to make the decision whether to use or forego the STL - for the whole company, for ever (it's going into some very core s/w).

我该跳哪种方式?超级安全丢失大量的构成C ++(imo,它不仅仅是语言定义),可能会遇到问题,或者需要添加大量的异常处理&现在可能还有一些其他的代码?

Which way do I jump? Super-safe & lose much of what constitutes C++ (imo, it's more than just the language definition) and maybe run into problems later or have to add lots of exception handling & maybe some other code now?

我试图去使用Boost,但1)我不知道是否会移植到每个嵌入式处理器我可能想使用和2)在他们的网站上,他们说,他们不保证/推荐嵌入式系统的某些部分(特别是FSM,这似乎很奇怪)。如果我去加速&

I am tempted to just go with Boost, but 1) I am not sure if it will port to every embedded processor I might want to use and 2) on their website, they say that they doesn't guarantee/recommend certain parts of it for embedded systems (especially FSMs, which seems weird). If I go for boost & we find a problem later ....

推荐答案


超级安全
构成C ++(imo,它比
只是语言定义)和
可能会遇到问题,或者有
添加大量的异常处理&
现在可能还有一些其他的代码?

Super-safe & lose much of what constitutes C++ (imo, it's more than just the language definition) and maybe run into problems later or have to add lots of exception handling & maybe some other code now?

我们在游戏世界里也有类似的争论,关于引用部分,你为什么会担心丢失C ++的构成?如果不务实,不要使用它。

We have a similar debate in the game world and people come down on both sides. Regarding the quoted part, why would you be concerned about losing "much of what constitutes C++"? If it's not pragmatic, don't use it. It shouldn't matter if it's "C++" or not.

运行一些测试。你能以满足你的方式来实现STL的内存管理吗?如果是,是值得的努力吗?很多问题STL和boost设计来解决只是简单不出来,如果你设计,以避免随意的动态内存分配... STL解决你面对的具体问题?

Run some tests. Can you get around STL's memory management in ways that satisfy you? If so, was it worth the effort? A lot of problems STL and boost are designed to solve just plain don't come up if you design to avoid haphazard dynamic memory allocation... does STL solve a specific problem you face?

很多人在紧张的环境中处理了STL,并对此感到满意。很多人只是避免它。有些人提出全新的标准。我不认为有一个正确的答案。

Lots of people have tackled STL in tight environments and been happy with it. Lots of people just avoid it. Some people propose entirely new standards. I don't think there's one right answer.

这篇关于嵌入式C ++:使用STL还是不行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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