I was going thru a program to reduce the size, and thought, gee, I can make that one smaller, it flashes a light with a timer. Well the commented out portion actually resulted in a program about a hundred bytes larger.
How can that be? Is there some optimazation routine in the compiler causing this?
Additionally, how can you possibly expect anyone to provide a meaning full answer if you don't provide complete code, specify which Arduino board, or show us both the new and old code?
If you need more memory, the best solution is just to pick up a board with more memory. Microoptimizations like this are pointless for hobby projects when boards with more memory are so cheap. If you're not at the limit yet, there's no point in optimizing code size, an unused byte of flash is a byte of flash wasted. If you really want to spend time on this, look at the generated code as suggested by Awol, but compilers are immensely complex, there's little point in trying to understand what's going on, unless there's a clear problem with the generated code, in which case you could report it to the GCC developers.
The heap lives in RAM (dynamic memory), not flash/program storage.
Instead of checking millis() >= prevMillis + interval, use millis - prevMillis >= interval. The former fails when millis overflows, the latter is always correct.
when i compiled you code w/o WiFi the non-commented out code need 946 bytes, the commented code 934 and a 3rd version to invoked msec = millis() and used msec elsewhere needed 846
hi sevenoutpinball
it's a pity that nobody answers you, but leaves on other considerations, because I frequently asked myself this question, and I would have liked to have a beginning of answer. Forums are sometimes good, but participants should know how to read a simple question, and answer it with relevance. No, instead, they go off in all directions, when it's not reminding you of the rules because you took a wrong step.
Otherwise it is common that the memory size used by the compiler is not consistent with the changes you just added or subtracted. If a useful answer could come?
if (millis() >= FlashTime) {
FlashTime = millis() + FlashInterval;
is less preferable than
if (millis() - FlashTime > FlashInterval) {
FlashTime = millis();
Do I have this correct?
But then again, we are making it do math and compare which takes longer than compare alone.
On memory, the flash stuff is only instructions and all variables are in the stuff called dynamic memory. Ok. I admit I hadn't thought about it that far. Makes sense tho.
Sure, ANYONE can provide a simple answer to a simple question. But, anybody experienced enough to provide an accurate / useful answer knows that compiler optimizations are extremely sophisticated and highly depend on both the nature of the complete program and the target processor it's being compiled for. So, if you don't understand why that information is required, then you definitely don't fit into that category.
I pondered using += but in the case where the FlashTime is already very old, you wouldn't get now plus an interval, you would get the past plus an interval that might still be in the past.
Which might be exactly what you want. It preserves the average number of flashes per unit time, which is not the case is you use FlashTime = millis(), and the latter will start to drift over time.