Proper size of the stack is important. It must be small enough to prevent memory wastage and large enough to accommodate real-time application requirements.
The ways to determine the size to allocate are-
-
Test the system under conditions that produce worst-case stack behavior – hard to predict/provoke.
-
Calculate the theoretical maximum stack requirement (using software tools).
Browsing for stack sizes through the Dalvik source history:
API 3 (Android 1.5) = 8KB
API 4-10 (Android 1.6 – Android 2.3.7) = 12KB
API 14-17 (Android 4.0 – Android 4.2.2) = 16KB
Garbage collection on the stack – The life span of variables on the stack is limited to the duration of the function. As soon as the function returns, the used stack memory will be freed.
Multi-Task Stack Sharing (MTSS) scheme
MTSS is a multi-task stack sharing technique, that grows the stack of a particular task into other tasks in the system after it has overflown its bounds. A possible configuration to use MTSS effectively is to deliberately reduce the memory provided to each task to below what it needs, and the deficit is recovered from stacks of other tasks. It helps to reduce the physical memory needed for an embedded system without reducing its reliability.