开发者

Points to be considered while designing or coding for lesser footprint deliverables

Please post the points one should keep in mind while designing or coding for lesser footprint deliverables for embedded systems.

I am n开发者_开发技巧ot giving compiler or platform details, as I want generic information. But, any specific information on Linux based OS is also welcome.


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:

  • no dynamic allocation
  • hence, no STL
  • no exception handling (obvious reasons)


There isn't a general answer, only ones specific to language/platform ... but

Small memory footprint ...

  1. Don't use Java, C#/mono, PHP, Perl, Python or anything with garbage collection
  2. Get as close to the metal as feasible, Use C
  3. Do alot of profiling to see where memory is getting allocated, if you are using dynamic allocation
  4. Ensure you prevent heap-fragmentation by allocating sensible chunks and sizes of the heap
  5. Avoid recursive functions especially those that use malloc(). Better allocating a chunk and passing a pointer around.
  6. use free() ;)
  7. Ensure your types are no bigger than required
  8. Turn on compiler optimizations

There will be more.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜