Skip to content
Preptima
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

Further reading