嵌入式环境中的STL [英] STL in embedded environment

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

问题描述

我是C ++程序员,多年来听到这样的说法,即STL在嵌入式环境中使用 不好 ,因此通常禁止将其用于我相信基于嵌入式环境的项目。Boost之类的STL库功能更强大,并且提供了更快,更强大的功能。更少的易于出错的开发方式(当然,语法没有什么威慑力,但是一旦我认为它是真正的宝藏)。此外,我发现STL很繁重,并且增加了代码荒谬的最终占用空间,因为因为它是模板化的,所以它只是一个将获得他要求的可编译代码,而不是整个STL。



我的问题是,这个民粹主义者(我周围至少有这样的窥视)认为STL的原因是 not 适用于嵌入式环境?



我确实看到了类似性质的问题,但是在这里我希望能在这里指出有关STL和嵌入式环境的利弊方面的帮助。



编辑:因此,在答复中,我将加总点:

1.可移植性问题

2.应对巨大的麻烦STL容器的分配

3. STL很难调试

4. STL中的深层函数调用会导致内联弱的编译器的性能降低(函子的功能无用!)

解决方案

STL存在很多问题(如 EASTL ),在嵌入式系统或小型系统中,主要问题通常是它管理(它的)内存。一个很好的例子是 Aquaria的PSP端口。 / p>

我的建议虽然是在进行假设之前的第一个测试,如果该测试表明您使用了过多的空间/处理器周期,则可能优化或两次优化可以将其推入可用的领域。



最后,boost是基于模板的,因此,如果您查看生成的模板代码的大小,则为'usable'。

编辑/更新:



要清除我的上一个声明(只是指Boost VS STL)。在C语言中,您可以(ab)使用相同的代码在共享相同标头(或布局)的不同结构上执行相同的工作,但是使用模板,每种类型都可能拥有自己的副本(我从未测试过是否有任何编译器即使启用了针对尺寸进行优化,它也足够聪明,可以做到这一点,即使它(在机器/装配级别)与刚生成的代码完全相同。 boost的优点是可读性强得多,并且塞满了很多东西,但是由于数量众多(有时很庞大)的头文件,这可能导致较长的编译时间。 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 environments and hence usually prohibited in usage for embedded environment 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天全站免登陆