设计或编码以减少占用空间的交付成果时要考虑的要点
请发布在为嵌入式系统设计或编码时应记住的要点,以减少占用空间。
我不会提供编译器或平台的详细信息,因为我想要通用信息。但是,也欢迎任何有关基于 Linux 的操作系统的具体信息。
Please post the points one should keep in mind while designing or coding for lesser footprint deliverables for embedded systems.
I am not giving compiler or platform details, as I want generic information. But, any specific information on Linux based OS is also welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
取决于你想达到多低。我目前正在为财务打印机编写代码,没有操作系统,主要规则是没有动态内存分配。有趣的是,我仍然说服工作人员编写完全现代的 C++ 代码;)。
实际上我们决定了一些规则:
Depends on how low you want to get. I'm currently coding for fiscal printers, and there's no OS, and the main rule is no dynamic memory allocation. The funny thing is that I still convinced the crew to code fully modern C++ ;).
Actually there are a few rules we decided upon:
没有通用答案,只有特定于语言/平台的答案...但是
内存占用小...
将会有更多。
There isn't a general answer, only ones specific to language/platform ... but
Small memory footprint ...
There will be more.
为了真正减少占用空间,请考虑直接进行组装。
我们都知道 C 或 C++ 中的 Hello World 是 20kb+(因为所有链接的默认库)。在汇编中,这种开销就消失了。正如评论中指出的那样,可以大大减少标准库。然而,事实仍然是,当编码汇编时可以获得的代码密度远高于编译器从高级语言生成的代码密度。因此,对于每个字节都很重要的代码,请使用汇编。
此外,当在处理器能力较差的设备上进行编程时,使用汇编语言进行编程可能是使程序足够快以使其足够实时以(例如)控制机器的唯一方法
for real low footprint consider doing Assembly directly.
We all know that Hello World in C or C++ is 20kb+(because of all the default libraries which get linked). In Assembly this overhead is gone. As pointed out in the comments one can reduce the standard libraries quite a bit. However, the fact remains that the code density you can get when coding assembly is much higher than a compiler will generate from a higher language. So for code where every byte matters, use assembly.
also when programming on devices with less capable processors, programming in assembly language might be your only way to do make the program fast enough for it to be realtime enough to (for instance) control machines
当面临这样的限制时,建议预分配内存以保证系统在负载下工作。诸如“对象池”之类的设计模式可用于共享系统内的资源。
C语言支持严格的资源(即内存和计算周期)控制。应认真考虑。
避免递归,因为它很容易被滥用并可能导致堆栈溢出情况。
When faced with such constraints, it is advisable to pre-allocate memory in order to guarantee that the system will work under load. A design pattern such as "object pooling" can be used to share resources within the system.
The C language enables tight resource (i.e. memory & compute cycles) control. It should be strongly considered.
Avoid recursion as it is easy to abuse and can result in stack overflow conditions.