STL在嵌入式环境中 [英] STL in embedded enviornment

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

问题描述

我是一名C ++程序员,多年来一直听说,STL是 不好用于嵌入式环境,因此通常禁止使用基于嵌入式环境的项目。我相信STL图书馆如Boost更强大,提供更快,更少的容易出错的手段的发展(当然语法是一点恐吓,但一旦过去,我认为这是一个真正的宝藏)。此外,我发现STL是重的,增加最终的代码荒谬的足迹,因为它是模板化的一个只有要获得可编译的代码,他要求,而不是整个STL。



我的问题是,这个民粹主义者的原因是什么(至少最偷窥我周围)认为调用STL的概念是不是 用于嵌入式环境?



我看到一个类似性质的问题,但我希望在这里指出一般关于STL和嵌入式环境的利弊。



编辑:所以这里我将回复的总和加起来:

1.可移植性问题

2.应对巨大的dymanice由STL容器分配

3. STL难以调试

4. STL中的深层函数调用导致编译器性能低下,编译器性能低,内联无效(函子的力量无用!)


解决方案

STL有很多问题(这里有 EASTL ),在嵌入式系统或小规模系统中,主要问题一般是它管理(它的)内存。一个很好的例子是 Aquaria的PSP港口。 / p>

我的建议是第一次测试,之后的假设,如果测试显示你使用太多的空间/处理器周期,最后,boost是基于模板的,所以如果你看看生成的模板代码的大小,那么它就是将受到与STL相同的影响。



编辑/更新:



up我的最后一个语句(这只是参考boost VS STL)。在C中,您可以(ab)使用相同的代码在共享相同标头(或布局)的不同结构上执行相同的作业,但是使用模板,每个类型可能会获得自己的副本(我从来没有测试任何编译器足够聪明地做到这一点,如果优化大小是enbaled),即使它完全相同(在机器/组装水平)作为刚刚生成的。 boost有一个优点是更清洁,阅读,并有更多的东西挤满了它,但是可能导致长的编译时间,由于一个copius的(一些庞大的)头。 STL收益,因为你可以传递你的项目,而不需要下载/陪同的提振。


I am a C++ programmer and over the years have been subjected to hearing the notion that STL is not good for use in embedded enviornments and hence usually prohibited in usage for embedded enviornment based projects.I believe STL libraries like Boost are far more powerful and provide a much more faster & less error prone means of development(ofcourse the syntax is little intimidating but once past that i think it's a real treasure).Also, I find the claims that STL is heavy and increases final footprint of code absurd because since it is templatized one is only going to get compilable code which he asked for and not the entire STL.

My question is what are the reasons for this this populist(atleast most peeps around me think so) notion which calls STL is not for embedded enviornment?

I do see a question of similar nature but herein i am expecting help in pointing out the pros and cons in general about STL and embedded enviornment here.

Edit: so here I will add up the points as the replies come in:
1. Portability Issues
2. coping with huge dymanice allocations by STL containers
3. STL is hard to debug
4. Deep function calls in STL results in low performance for compilers weak with inlining (power of functors useless!)

解决方案

STL has quite a few problems with it(as documented here by EASTL), on an embedded system, or small scale system, the main problem is generally the way in which it manages (its) memory. a good example of this was the PSP port of Aquaria.

My advise though is first test, before following assumptions, if the test are shows your using just too much space/processor cycles, then maybe an optimization or two could push it into the realm of 'usable'.

Finally, boost is template based, so if your looking at the size of generated template code, it'll suffer the same as STL.

Edit/Update:

To clear up my last statement (which was just refering to boost VS STL). In C, you can (ab)use the same code to do the same job on different structures sharing the same header (or layout), but with templates, each type might get its own copy (I've never test if any compilers are smart enough to do this if 'optimize for size' is enbaled), even though it exactly the same(on a machine/assembly level) as one thats just been generated. boost has the advantage of being a lot cleaner to read, and having far more things crammed into it, but that can lead to long compile times due to a copius amount of (somtimes huge) headers. STL gains because you can pass your project around and not require a download/accompanyment of boost.

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

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