mediumConceptDesignMidSeniorStaff
How do you size the stack and the heap on a device with a fixed RAM budget?
Stack and heap sizing on fixed RAM starts from the link map, worst-case call depth and interrupt nesting. Measure stack high-water marks with fill patterns, avoid unbounded heap allocation, and prefer fixed pools allocated at startup for predictable firmware behaviour.
5 min readUpdated 2026-08-15
Answer
Short answer
Budget globals from the link map, size stack from worst-case calls plus nested interrupts, prove it with high-water testing, and replace general heap use with fixed pools.
Was this answer helpful?
Likely follow-ups
- Where would you place a buffer that must survive a warm reset but not a power cycle?
- How would you prove to a safety reviewer that the deepest call path fits in the allocated stack?
- If a third-party TLS library insists on malloc, how do you contain it?
- What changes about your RAM budget once you introduce an RTOS with one stack per task?
Related questions
- Why do low-latency systems preallocate arenas instead of calling the general-purpose allocator on the hot path?hardAlso on memory-management7 min
- How do you use a watchdog timer to recover a wedged device without hiding the bug that wedged it?hardAlso on firmware5 min
- How do you design a custom memory allocator to eliminate fragmentation and guarantee deterministic execution time in a safety-critical embedded system?hardAlso on memory-management3 min
- How do retain cycles happen in Swift closures and delegates, and how would you find one in an app that is slowly leaking memory?mediumAlso on memory-management4 min