工作站和嵌入式程序员的心态差异
您认为在桌面环境(Windows、Linux 等)上工作的程序员与在嵌入式系统上工作的程序员在思维方式上有什么区别?
我能想到的一个简单的例子是,在嵌入式环境中,我总是检查malloc是否不为NULL。 我见过的大多数代码,目标桌面肯定不会勤于检查 malloc 返回值。
还有其他心态差异的例子吗?
What do you think are the difference in mindset between a programmer doing work for a desktop environment (windows, linux, whatever...) and someone doing work on an embedded system?
A simple example I can think of is that in an embedded environment, I always check that a malloc is not NULL. Most code I have seen that target desktops is certainly not diligent in checking malloc return value.
Any other examples of mindset differences?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有趣的是,您在示例中特别提到了 malloc() 。
在我工作过的每个硬实时、深度嵌入式系统中,内存分配都是专门管理的(通常不是堆,而是固定内存池或类似的东西)......并且,只要有可能,所有内存分配都是在初始化期间预先完成。 这比大多数人想象的要容易得多。
malloc() 容易产生碎片,具有不确定性,并且不区分内存类型。 使用内存池,您可以拥有位于/从超快速 SRAM、快速 DRAM、电池支持 RAM(我见过)等中提取的池...
还有一百个其他问题(回答您最初的问题) ),但是内存分配是一个很大的问题。
另外:
Funny that you mention malloc() specifically in your example.
In every hard-real-time, deeply embedded system that I've worked on, memory allocation is managed specially (usually not the heap, but fixed memory pools or something similar)... and also, whenever possible, all memory allocation is done up-front during initialization. This is surprisingly easier than most people would believe.
malloc() is vulnerable to fragmentation, is non-deterministic, and doesn't discrminate between memory types. With memory pools, you can have pools that are located/pulling from super fast SRAM, fast DRAM, battery-backed RAM (I've seen it), etc...
There are a hundred other issues (in answer to your original question), but memory allocation is a big one.
Also:
桌面程序员认为资源实际上是无限的。 内存、计算能力、驱动空间。 这些永远不会用完。 嵌入式程序员专注于所有这些。
哦,嵌入式程序员还经常需要担心内存对齐问题。 桌面编码员则不然。 Arm 芯片很关心。 x86 芯片则不然。
Desktop programmers view resources as practically unlimited. Memory, computing power, drive space. Those never run out. Embedded programmers focus intently on all of those.
Oh, and embedded programmers also often have to worry about memory alignment issues. Desktop coders don't. The Arm chips care. x86 chips don't.
在桌面环境中,有这样的想法:“嘿,我可以随时发布更新或补丁来修复此问题。” 在嵌入式设计中,您会得到更多“这必须起作用,因为我们不想召回设备或发布更长的修补程序”。
I desktop environment there's the idea that "hey I can always release an update or patch to fix this later." In embedded design, you get more "this has to work cause we don't want to recall the device or release an even longer patching program."
大小事项
size matters
有两件事 - 正如 Suroot 已经提到的,一旦发布桌面应用程序,它不一定是“永远”,尤其是现在。
但在嵌入式中,一旦你“运送它”,它就正在前往火星的途中,所以你将无法将其拉回。
主要区别之一是嵌入式程序员通常对高效代码和内存管理更加关注 - 台式机运行可怕的代码非常快,而嵌入式则不然。
2 things - as Suroot already mentioned, once you release a desktop app, it doesn't have to be "forever", especially nowadays.
But in embedded, once you "ship it", it's on its way to Mars so you're not going to be able to pull it back.
Also one of the major differences are that embedded programmers are generally a LOT more conscious about efficient code and memory management - desktops run horrible code really fast, embedded doesn't.