工作站和嵌入式程序员的心态差异

发布于 2024-07-13 17:04:30 字数 196 浏览 4 评论 0原文

您认为在桌面环境(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

相思碎 2024-07-20 17:04:30

有趣的是,您在示例中特别提到了 malloc() 。

在我工作过的每个硬实时、深度嵌入式系统中,内存分配都是专门管理的(通常不是堆,而是固定内存池或类似的东西)......并且,只要有可能,所有内存分配都是在初始化期间预先完成。 这比大多数人想象的要容易得多。

malloc() 容易产生碎片,具有不确定性,并且不区分内存类型。 使用内存池,您可以拥有位于/从超快速 SRAM、快速 DRAM、电池支持 RAM(我见过)等中提取的池...

还有一百个其他问题(回答您最初的问题) ),但是内存分配是一个很大的问题。

另外:

  • 尊重/了解硬件平台
  • 不会自动假设硬件是完美的甚至是功能性的
  • 对某些语言方面和功能的了解 可能导致事情快速偏离方向的功能(例如,C++ 中的异常)
  • 了解 CPU 负载和内存利用率
  • 了解中断、抢占以及对共享数据的影响(在绝对必要的情况下 - 共享数据越少越好)
  • 大多数嵌入式系统是数据/事件驱动的,而不是轮询的; 当然也有例外
  • 大多数嵌入式开发人员对状态机和状态行为/建模的概念非常满意

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:

  • Respect for / knowledge of the hardware platform
  • Not automatically asssuming the hardware is perfect or even functional
  • Awareness of certain language apects & features (e.g., exceptions in C++) that can cause things to go sideways quickly
  • Awareness of CPU loading and memory utilization
  • Awareness of interrupts, pre-emption, and the implications on shared data (where absolutely necessary -- the less shared data, the better)
  • Most embedded systems are data/event driven, as opposed to polled; there are exceptions of course
  • Most embedded developers are pretty comfortable with the concept of state machines and stateful behavior/modeling
忘东忘西忘不掉你 2024-07-20 17:04:30

桌面程序员认为资源实际上是无限的。 内存、计算能力、驱动空间。 这些永远不会用完。 嵌入式程序员专注于所有这些。

哦,嵌入式程序员还经常需要担心内存对齐问题。 桌面编码员则不然。 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.

全部不再 2024-07-20 17:04:30

在桌面环境中,有这样的想法:“嘿,我可以随时发布更新或补丁来修复此问题。” 在嵌入式设计中,您会得到更多“这必须起作用,因为我们不想召回设备或发布更长的修补程序”。

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."

笑咖 2024-07-20 17:04:30

大小事项

size matters

坏尐絯 2024-07-20 17:04:30

有两件事 - 正如 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文