Very large program storage generate in Arduino

Development environment specific, Arduino, Eclipse, VS2013,Em::Blocks etc
hamsafar_a85
Posts: 11
Joined: Tue May 09, 2017 10:48 am
Contact:

Very large program storage generate in Arduino

Post by hamsafar_a85 » Tue May 09, 2017 11:41 am

I compile my project for UNO and my program size is about 16kB but when compile it for Maple mini code is too big!!!
Sketch uses 85056 bytes (76%) of program storage space. Maximum is 110592 bytes.
Global variables use 6272 bytes of dynamic memory.

How can I reduce the program space?

stevestrong
Posts: 1748
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Very large program storage generate in Arduino

Post by stevestrong » Tue May 09, 2017 11:53 am

Avoid using

Code: Select all

blabla my_variable = new some_fancy_class;
The "new" constructor will most probably cause the flash increase.

victor_pv
Posts: 1681
Joined: Mon Apr 27, 2015 12:12 pm

Re: Very large program storage generate in Arduino

Post by victor_pv » Tue May 09, 2017 12:33 pm

Another member of the forum created this tool to analyze the .map file:
http://danieleff.com/stm32/map_analizer/

If you don't use "new" or think that doesn't account for all the space difference, get your file from your build folder, upload it, and will help you find what's taking space. If you have doubts with anything you find there post back to see if someone can give you extra advise.

ag123
Posts: 770
Joined: Thu Jul 21, 2016 4:24 pm

Re: Very large program storage generate in Arduino

Post by ag123 » Tue May 09, 2017 7:09 pm

check inside your platforms.txt on the particular core e.g. F1 or F4 these flags should be specified on the gcc and g++ compile flags

Code: Select all

-fmessage-length=0
-fsigned-char
-ffunction-sections
-fdata-sections
-ffreestanding
-fno-move-loop-invariants
	-fno-exceptions
	-fno-rtti
	-fno-use-cxa-atexit
	-fno-threadsafe-statics
	-nostdlib
	-Xlinker --gc-sections
	--specs=nano.specs
based on what i noted those indented flags have the most observable effect on size. note that if you specify those flags and you get compile errors, then most likely you are using c++ features (e.g. exceptions) or standard lib features that cause the code to be bloated up
e.g. for small code size c++ exceptions can't be achieved, u'd either need to live without c++ exceptions or live with a big code size

hamsafar_a85
Posts: 11
Joined: Tue May 09, 2017 10:48 am
Contact:

Re: Very large program storage generate in Arduino

Post by hamsafar_a85 » Wed May 10, 2017 4:34 am

stevestrong wrote:Avoid using

Code: Select all

blabla my_variable = new some_fancy_class;
The "new" constructor will most probably cause the flash increase.
Thanks, but why when I compile with UNO size of flash is 16KB?

hamsafar_a85
Posts: 11
Joined: Tue May 09, 2017 10:48 am
Contact:

Re: Very large program storage generate in Arduino

Post by hamsafar_a85 » Wed May 10, 2017 4:40 am

victor_pv wrote:Another member of the forum created this tool to analyze the .map file:
http://danieleff.com/stm32/map_analizer/

If you don't use "new" or think that doesn't account for all the space difference, get your file from your build folder, upload it, and will help you find what's taking space. If you have doubts with anything you find there post back to see if someone can give you extra advise.
Thanks,with analyze in your link:
6223 used / 17408 total RAM
178275 used / 110592 total FLASH
It's different with what arduino say!!
My .map file:
https://ufile.io/ch3r6

ag123
Posts: 770
Joined: Thu Jul 21, 2016 4:24 pm

Re: Very large program storage generate in Arduino

Post by ag123 » Wed May 10, 2017 6:39 am

check in platforms.txt that these compile flags are specified in gcc, g++ compile commands

Code: Select all

-nostdlib
-Xlinker --gc-sections
-specs=nano.specs
-fno-exceptions
-fno-rtti
-fno-use-cxa-atexit
-fno-threadsafe-statics

User avatar
RogerClark
Posts: 7171
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Very large program storage generate in Arduino

Post by RogerClark » Wed May 10, 2017 10:14 am

The problem with new causing the binary size to be much larger than expected was partially fixed last year in this commit

https://github.com/rogerclarkmelbourne/ ... 2a824d80b7

By the addition of new.cpp

However, it does not seem to work in all circumstances

Someone will need to investigate why the functions in new.cpp are not being called in this case

hamsafar_a85
Posts: 11
Joined: Tue May 09, 2017 10:48 am
Contact:

Re: Very large program storage generate in Arduino

Post by hamsafar_a85 » Sat May 13, 2017 7:30 am

ag123 wrote:check in platforms.txt that these compile flags are specified in gcc, g++ compile commands

Code: Select all

-nostdlib
-Xlinker --gc-sections
-specs=nano.specs
-fno-exceptions
-fno-rtti
-fno-use-cxa-atexit
-fno-threadsafe-statics
Thanks,I add all of your flags but no change occure!

stevestrong
Posts: 1748
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Very large program storage generate in Arduino

Post by stevestrong » Sat May 13, 2017 7:32 am

Can you show us your code?

Post Reply