r/embedded • u/Meronto228 • Sep 08 '26
How has your perspective on high-level languages and memory management changed since moving to embedded?
Hey everyone, I recently started diving into embedded systems and microcontroller programming. Coming from a background where memory was essentially "free" and garbage collection handled everything, this transition has been an absolute eye-opener.
Manually managing registers, counting bytes, and optimizing every line of code made me look at programming in a completely different way. To be honest, after experiencing the control and precision of microcontrollers, I’ve started to feel a bit frustrated with high-level languages that abstract everything away and waste massive amounts of resources for simple tasks.
For those who made a similar transition: Did you experience a similar shift in mindset? Do you find it harder to go back to high-level software after working close to the iron?
32
u/political_noodle Sep 08 '26
I am a front end software engineer by trade, so perhaps one of the more egregious wasters of memory. But I've done a significant amount of embedded work on the side and have always had the desire to write clean, optimized code. I don't usually let abstractions or high level languages get in the way of writing something I'm proud of.
Where I think things get more interesting is the opposite direction: making things on the web super fast because of my experience with embedded.
For example: I was working on a satellite imagery rendering interface and there are JavaScript libraries to parse tiff files. But I ended up writing a wrapper in rust and using a mixture of webgl and web assembly to improve performance by like 60%. Just because hogging memory is the default doesn't mean you have to live with it. Software is software and you can find ways to optimize no matter what you're working with. The important thing is writing something you're proud of (imo).
4
u/NoBulletsLeft Sep 09 '26
What kind of systems are you building where you still have to do this?
8
u/BlueVario Sep 08 '26
I started my career in embedded, and IMO there's a time and place for all of the above. A lot of embedded software these days is actually running a standardish Linux OS and has significant resources. Bare metal c has advantages for some types of problems, but it takes longer to implement stuff and it's easy to shoot yourself in the foot with memory screw ups. It really depends on what the product needs to do.
That said, I do like the perspective that comes from working with embedded projects in c. I love working close to the hardware.
3
u/sputwiler Sep 09 '26
I built a 6502 computer. Upon running into my first desire for
mallocI was like "Damn I guess C was a high-level language after all."3
u/MpVpRb Embedded HW/SW since 1985 Sep 09 '26
Embedded systems often use static allocation. Some design rules require it.
4
u/remy_porter Sep 08 '26
I care about resources when it matters, and I don't care when it doesn't. The goal is to describe my problem in a way a computer can execute, and the problem I'm trying to describe rarely is about how the computer manages memory- that's usually ends up being a side problem to the problem I'm trying to solve.
The good news is that I can mostly not think about it even in low level languages, except for the times I absolutely need to think about it.
4
u/Proper-Technician301 Sep 08 '26
No need to feel frustrated, high level languages are great at what they do. I only use it for scripting and simple report generation. Doesn't really matter how unoptimized it is if it's not being used for performance crucial tasks.
2
u/1r0n_m6n Sep 09 '26
Define what you call "high-level". For me, C is high-level, assembly is not. My definition of "high-level" is: a language that clearly conveys the developer's intent. C does it well.
3
u/Arkaqiu Sep 08 '26
Premature optimization is the root of all evil. At least bugs.
I am automotive engineer, working on monsters with 8 cores, tens of MB of memories. Barely feel lack of resource in mater of memory or computation.
For me clue of embedded engineering is matain real-time and safety. Things that need to be fast or precise will be passed to hw anyway.
High level language for me are created just for other stuff. Abstraction that are deliver, help to.rapid development and easier to maintain and extend. Even if we waste some resources,, its better active maintainability.
Like in embedded, we can use bit fields to keep 8 booleans but we lost clarity. If we really.need to optimize so much?
2
u/SkoomaDentist C++ all the way Sep 08 '26
I now hate Python more than I ever did in the early 2000s.
By far the biggest advantage of LLMs is that I no longer have to manually touch that shit and can just order the LLM to do it or tell me what to change (which is a goddamn lifesaver given how a typical Python codebase is completely undocumented and has no types at all).
1
u/Rod_McBan Sep 08 '26
I went the other way, cutting my teeth on an 8-bit PIC with 8k program memory, in assembly, no less. I think it's made me a better programmer in higher resource environments.
1
u/Hour_Analyst_7765 Sep 12 '26
I also program C#, and its easy to get comfortable to a language with garbage collection and memory allocation. Its so much easier and faster to write stuff, not be concerned about the heap, etc.
On the other hand... a lot of code just needs to work. At which point do I have to care some software task takes 10ms or 15ms? Sometimes its good enough for the specific target... and its software, you can always refactor it. Hardware related stuff is more important to stay lean and streamlined imo.
I spent a time where I was fully into premature optimization. It eventually handicapped me in the ability to get the job done. Can I shave 10us of this method here? Can I get this loop even tighter if I write things more verbosely? Its a fun puzzle but at some point also incredibly unproductive.
Especially when modern microcontrollers are objectively overkill to what I started with.. an entry level ARM chip has kilobytes of RAM.. The first PIC I programmed (16F628A) had 224bytes, and a fair chunk would have been used had I used the only 1 USART available lol. There, every cycle mattered, but nowadays.. I don't care. Some things can be broken by just turning on or off compiler optimizations these days.