algia71
November 24, 2021, 5:02pm
1
Hi. Ultra newbie here. This program does work, despite exceeding the available RAM (2K) on my Nano:
int b[10000];
void setup() {
Serial.begin( 115200 );
while( !Serial );
for(int i = 0; i < 10000; ++i)
b[i] = i;
for(int i = 0; i < 10000; ++i)
Serial.println(i);
}
void loop() {
}
The compiler states:
1658 byte (5%) of program space
188 byte (9%) of dynamic memory
How is it possible? I tried to search this forum and the internet, without any success.
6v6gt
November 24, 2021, 5:05pm
2
algia71:
Serial.println(i);
That is not a particularly severe test. Try:
Serial.println( b[ i ] ) ;
A compiler optimisation has exclude the worst of it.
1 Like
J-M-L
November 24, 2021, 5:06pm
3
The optimizer notices you don’t use the b array in any meaningful way and thus gets rid of that code altogether
1 Like
algia71
November 24, 2021, 5:16pm
4
OK, thank you, now begins to became clearer. So the rule is: you can declare whatever you want; you can even write to it; but the compiler warns/stops you only when you try to read from it. Am I correct?
algia71
November 24, 2021, 5:27pm
5
Could you please suggest a link to documentation that explains deeply how the optimizer works? Thank you
alto777
November 24, 2021, 5:31pm
6
If you are indeed an "Ultra newbie", a deeply explanation of the optimizer is going to be a giant waste of you time.
Just sayin'.
a7
algia71
November 24, 2021, 5:38pm
7
I'm an ultra newbie, but in Arduino stuff. Anyway thank you for wasting your time answering with no additional useful info.
1 Like
6v6gt
November 24, 2021, 5:58pm
8
It's all here and should be more or less self explanatory: Optimize Options (Using the GNU Compiler Collection (GCC))
Arduino for boards like the Uno etc. is currently at C++11
1 Like
J-M-L
November 24, 2021, 6:29pm
10
And compiler uses -O3
So now you just have to look at what all those flags do (if that explains @alto777 ’s remark)
-fauto-inc-dec
-fbranch-count-reg
-fcombine-stack-adjustments
-fcompare-elim
-fcprop-registers
-fdce
-fdefer-pop
-fdelayed-branch
-fdse
-fforward-propagate
-fguess-branch-probability
-fif-conversion
-fif-conversion2
-finline-functions-called-once
-fipa-modref
-fipa-profile
-fipa-pure-const
-fipa-reference
-fipa-reference-addressable
-fmerge-constants
-fmove-loop-invariants
-fmove-loop-stores
-fomit-frame-pointer
-freorder-blocks
-fshrink-wrap
-fshrink-wrap-separate
-fsplit-wide-types
-fssa-backprop
-fssa-phiopt
-ftree-bit-ccp
-ftree-ccp
-ftree-ch
-ftree-coalesce-vars
-ftree-copy-prop
-ftree-dce
-ftree-dominator-opts
-ftree-dse
-ftree-forwprop
-ftree-fre
-ftree-phiprop
-ftree-pta
-ftree-scev-cprop
-ftree-sink
-ftree-slsr
-ftree-sra
-ftree-ter
-funit-at-a-time
-falign-functions -falign-jumps
-falign-labels -falign-loops
-fcaller-saves
-fcode-hoisting
-fcrossjumping
-fcse-follow-jumps -fcse-skip-blocks
-fdelete-null-pointer-checks
-fdevirtualize -fdevirtualize-speculatively
-fexpensive-optimizations
-ffinite-loops
-fgcse -fgcse-lm
-fhoist-adjacent-loads
-finline-functions
-finline-small-functions
-findirect-inlining
-fipa-bit-cp -fipa-cp -fipa-icf
-fipa-ra -fipa-sra -fipa-vrp
-fisolate-erroneous-paths-dereference
-flra-remat
-foptimize-sibling-calls
-foptimize-strlen
-fpartial-inlining
-fpeephole2
-freorder-blocks-algorithm=stc
-freorder-blocks-and-partition -freorder-functions
-frerun-cse-after-loop
-fschedule-insns -fschedule-insns2
-fsched-interblock -fsched-spec
-fstore-merging
-fstrict-aliasing
-fthread-jumps
-ftree-builtin-call-dce
-ftree-loop-vectorize
-ftree-pre
-ftree-slp-vectorize
-ftree-switch-conversion -ftree-tail-merge
-ftree-vrp
-fvect-cost-model=very-cheap
-fgcse-after-reload
-fipa-cp-clone
-floop-interchange
-floop-unroll-and-jam
-fpeel-loops
-fpredictive-commoning
-fsplit-loops
-fsplit-paths
-ftree-loop-distribution
-ftree-partial-pre
-funswitch-loops
-fvect-cost-model=dynamic
-fversion-loops-for-strides
Don't be rude. @alto777 's comment was entirely legitimate.
system
Closed
May 23, 2022, 7:30pm
12
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.