I have all global variables in my project. Since RAM data size has almost become full, i wanted to replace some of the global variables with local variables in functions. But each local variable declaration seems to take up RAM space as if it is a global variable;
Assume I have few global variables and the data size is 10 bytes
After compiling, this again increases the data size to 30. What is the point of using local variables in this scenario? It works as if the the variables are declared globally. Shouldn't the data size be global variables 10 bytes + maximum local variable size i.e 10 bytes = 20 bytes total?
Is it better to declare the 10 variables as global once and save the 10 bytes?
The compiler don't know at first sight whether you will instantiate these functions at the same layer of the program or not. If you call all them sequentially, really could reuse the same memory space for all that functions, but if you call, for instance function1() inside an ISR vector ( which in fact is not an appropriate deed ) and if you call function2() inside the main(), both memories resourses will not be released, being used at same time.