Does anyone know why a blank Arduino Sketch Uses 450 Bytes of Program Storage Space and has 9 Bytes of Global Variable? Why?
How does this compare with other AVR compilers?
Does anyone know why a blank Arduino Sketch Uses 450 Bytes of Program Storage Space and has 9 Bytes of Global Variable? Why?
How does this compare with other AVR compilers?
Compilers are smarter than us. If you allocate memory with no value, it is set aside and that is all. When you set a value, then a value is et in global to remember ot. No surprise to me, but I work with these for over 40 years. The loop may be optimized out of existence. I have seen this too. The behaviour is predictable IF you know how they generate code.
Compilers are smarter than us. If you allocate memory with no value, it is set aside and that is all. When you set a value, then a value is et in global to remember ot. No surprise to me, but I work with these for over 40 years. The loop may be optimized out of existence. I have seen this too. The behaviour is predictable IF you know how they generate code.
thank you Clem, but thiss brings me back to pondering why a blank Arduino sketch would have the 9 bytes global variables when we have not used any yet.
what are those 9 bytes for variables for?
i wish we can compare it with other compilers or AVR IDE.
i believe in other AVR IDEs it goes something like this
int main(){
/*main is like the setup section of arduino*/
/**this is the loop section**/
while(1)
{
//codes for the loop section here
}
/**end of loop section**/
}
if we compile this will we get similar byte usage with the Arduino.
I am trying to understand one of the pros and cons of a given IDE.
Here is a comparison sketch (a version of Blink) using an int main() while loop style vs the Arduino setup() loop()... in the same Arduino IDE
int main() while loop:
Arduino setup() loop() style:
I don't know what is in the setup() loop() style that adds too many bytes in the program storage space. it is about double compared to using an int main() while loop.
Another variation of the int main() while loop:
If you use the AVR Studio (I am using version 6) you see that the setup() and loop() functions can be defined to obtain the behaviour of the sketch IDE. Just the fact that you declare these functions mean that you need a main function entry point, a variable to manage the loop() and the two function pointer themselves for setup() and loop(). The concept is that with direct language-to-machine management you can do almost what you want while with Arduino users take advantage of some simplifications but pay this with few more memory usage due the default minimal components that are preset.
As a matter of fact, it is not a low level programming, as you have the setup() and loop() functions and the relative minimal environment defined there. I am almost sure that this does not depends on the compiler itself (but the compiler may change the optimisations for sure in some cases) because with the same compiler a real C++ code written in AVR Studio generates a more compact binary than the same equivalent code with the arduino IDE.
As far as what is my experience, this increased optimisation and reduced size of the binary will occur also using the same architecture of a "sketch" treated more seriously as a C++ source program instead of the pre-cooked version supported by the IDE.
Enrico
Please select option to show all details and run these tests again. When you do you will see what code is added and can surmise why the differences.
clem
Enrico, could you please try and compile a blink program in the AVR Studio that you mentioned?
I would like to see how many bytes it uses. Your contribution is much appreciated.
Thanks.
Enrico, could you please try and compile a blink program in the AVR Studio that you mentioned?
I would like to see how many bytes it uses. Your contribution is much appreciated.
Thanks.
Orlando, what do you mean as a blink program ?
I'll do asap.
Enrico
Could you try a main approach versus a void setup/loop? I wrote the internals until my browser crashed and nothing recovered.
clem57 Ok, but there is something that I have not clear. Welcome to make a test anyway, but let me explain.
Need to be an empty program? Without loop, you mean a simple main that does not includes the wile(forever) function? Let me know what is the exact need. I can try it tomorrow just because I should reload the AVR Studio VM machine while in this moment I am working on the Raspberry PI.
Enrico