I need to calculate the stack memory consumption of my program.
gcc's -fstack-usage
only calculates the stack usage of function, but does not include an additional function call in that function as far as I understand.
void test1(){
uint32_t stackmemory[100];
function1(); //needs aditional stack, say 200 Bytes
uint32_t stackmemory2[100];
}
void test2(){
uint32_t stackmemory[100];
uint32_t stackmemory2[100];
function1(); //needs additional stack, say 200 Bytes
}
Which test() function uses less stack? I would say test1(), as the stack is freed after the function1() call. Or does this depend on the optimization level -Os/-O2...?
Does the compiler allocate memory in test1() for all its static variables, as soon as the function is entered? Or is stackmemory2[100] allocated when the line is reached?
See Question&Answers more detail:os