Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Program too big. (Read 1915 times)
Bunzino69
Newbies
*
Offline


Posts: 9
Joined: Apr 24th, 2018
Program too big.
Dec 10th, 2021 at 5:49pm
Print Post  
I've come across something I can't explain. I am on a VS2019 platform using the latest Visual Micro extension and programming a genuine Adruino Nano (32K flash). 

I've reached the limits of the flash memory available. When compiled, the code equates to 30,486 byes used of 30,720 available. In one section of my code I have a "switch" statement. If I add another switch condition and the below lines of code, the compiled size jumps to 31,180 bytes therefore the VM "too big" message appears. Even if I remove the Serial.println statement (blank between case and break), I still get a compile size of 31,156.

case 'X':
     Serial.println(EEPROM.readByte(Addr_MCnum1));
break;

Has anyone come across this or can anyone explain why this is happening?

b
  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12186
Location: United Kingdom
Joined: Apr 10th, 2010
Re: Program too big.
Reply #1 - Dec 10th, 2021 at 6:19pm
Print Post  
It is difficult to know exactly without seeing the rest of the code. 

The compiler performs optimization, therefore using certain methods for the first time in code can cause larger increase than would be expect by one line of code. Performing an EEPROM read in a println() would in theory be okay but no idea how well the compiler copes with some syntax.

Ensuring that you have the configuration set to "Release" might help reduce memory usage, if you are that close to the limit. 

The info in the yellow box will above will help us see what optimization and other settings that you have. It is always useful to post that.
  
Back to top
IP Logged
 
Bunzino69
Newbies
*
Offline


Posts: 9
Joined: Apr 24th, 2018
Re: Program too big.
Reply #2 - Dec 10th, 2021 at 6:44pm
Print Post  
Thank you for the quick reply! Smiley

I can confirm the configuration is set to Release.

I have attached the two verbose compile outputs in one text file. The output without the switch statement will be listed first. The output with the switch statement starts after "==========" separator.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2695
Joined: Feb 13th, 2019
Re: Program too big.
Reply #3 - Dec 13th, 2021 at 10:50am
Print Post  
Thanks for the output, the compiler is already optimizing for size.

Would it be possible to zip and email the entire solution so we can check if there is anything else which could be done?
  
Back to top
IP Logged
 
PMF
Newbies
*
Offline


Posts: 5
Joined: Nov 24th, 2021
Re: Program too big.
Reply #4 - Jan 4th, 2022 at 9:01pm
Print Post  
A switch statement is a difficult thing to optimize. The optimal implementation depends not only on the number of cases in the statement but also on their values. The compiler might use a series of conditional jumps if there are few cases only (basically using a series of if-else-else). If the number of cases grows, a lookup table is the better solution (a table that contains the target address for each case). This is faster, but has the drawback that also empty cases need handling (e.g if you have cases "A", "B", and "D", the table still needs to have an entry for "C"). So it is possible that due to the single added case, the compiler switches to using a (larger) table, causing this extra memory requirement. Even if the compiler is told to optimize for code size, it will at one point start trading off size for speed.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint