Forum Discussion
Altera_Forum
Honored Contributor
10 years agoThe required stack and heap size strongly depend on what your code does and how it is structured.
Stack size usually increase if you use many levels of function calls (main calls fn1 which calls fn2 which calls fn3...) and/or if you use a lot of local variables. This is because each function call pushes some data on the stack, i.e. function parameters, return address, local variables: then the stack grows momentarily until the function returns. More nested calls you have, more the stack will grow. For the same reason the grow could be 'explosive' if you use recursive calls. Heap size substantially depends on manually allocated variables. If your code doesn't use functions like malloc or calloc, you virtually don't need heap at all. Clearly, you must also consider any library functions you are using. They will add some stack -and possibly heap- usage to that stricly required by your code.