对于STL或!STL,这就是问题 [英] To STL or !STL, that is the question

查看:93
本文介绍了对于STL或!STL,这就是问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

毫无疑问,我会选择对大多数C ++编程项目使用STL。这个问题最近提交给我,有没有什么情况下你不会使用STL?...

Unquestionably, I would choose to use the STL for most C++ programming projects. The question was presented to me recently however, "Are there any cases where you wouldn't use the STL?"...

我想到的越多,更多我意识到,也许应该有这样的情况,我选择不使用STL ...例如,一个真正大,长期的项目,其代码库预计将持续多年...也许一个定制的容器解决方案,准确地适合项目需求是值得的初始开销?

The more I thought about it, the more I realized that perhaps there SHOULD be cases where I choose not to use the STL... For example, a really large, long term project whose codebase is expected to last years... Perhaps a custom container solution that precisely fits the projects needs is worth the initial overhead? What do you think, are there any cases where you would choose NOT to STL?

推荐答案

有严格内存要求的项目,例如嵌入式系统可能不适合STL,因为可能难以控制和管理从堆中取出和返回的内容。正如Evan提到的,编写合适的分配器可以帮助解决这个问题,但是如果你计算每个使用的字节或者关心内存碎片,可能更聪明的为你的特定问题定制一个解决方案,因为STL已经优化

Projects with strict memory requirements such as for embedded systems may not be suited for the STL, as it can be difficult to control and manage what's taken from and returned to the heap. As Evan mentioned, writing proper allocators can help with this, but if you're counting every byte used or concerned with memory fragmentation, it may be wiser to hand-roll a solution that's tailored for your specific problem, as the STL has been optimized for the most general usage.

您还可以选择不对特定情况使用STL,因为存在不在当前标准中的更多适用容器,例如boost: :array或boost :: unordered_map。

You may also choose not to use STL for a particular case because more applicable containers exist that are not in the current standard, such as boost::array or boost::unordered_map.

这篇关于对于STL或!STL,这就是问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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