Stack Sizing by powers of 2?


I know arbitrary stack size can be used but is there any particular benefit to keeping stack sizes in powers of 2 (e.g. 1024 → 2048 → 4096)? I am trying to optimize the space that I am using in RAM on my device and seeing where I can minimize my stack usage.


There is no real advantage to keeping stack sizes powers of 2. They should be a multiple of the heap allocation quantum (if dynamically created), or for a MPU restricted task, the MPU region quantum.

1 Like

As per richard-d - the programmable region size of some memory protection units (MPUs) are restricted to power of two sizes. The only time I would use a power of two stack is when using such an MPU to detect writes outside of the stack region.

1 Like