Search code examples
c++embeddedflash-memory

Reduce the size of Flash memory embedded cpp


After a lot of research i could not find any solution to my question (if i did i woudln't be here ...) I'm looking for solutions that permits me to reduce the flash memory used by my program.

I'm programming an embedded c++ programm and when i Flash my electronic card in release mode everything is fine cause it doesn't overflow the space of the flash memory, but that is not the case when i do it in Debug mode... I want to know if it is possible to find functions (my goal is to do it without reducing the code) that could reduce Flash memory.I already thought about defragmentation but I don't find how to do it in embedded even though i don't even know if i can ... I also tried the -Os cmd from gcc but without any big success

So I'm taking any advices or support and i'll be there at any question about my issue ;)

Thanks !


Solution

    1. Look at your map file. Is there something there you don't expect? Functions you aren't expecting (like floating point, or exception handling, etc.) or something unreasonably large?
    2. Turn on optimization except for the file you're interested in.
    3. Make sure you've actually got optimizations turned on (look at the build log and ensure that you've got -Os being passed to each compile step)
    4. Consider link time optimizations, but don't expect miracles

    Welcome to embedded programming. 90% of the job is figuring out how to stuff the never ending requirements into the memory available. Rinse and repeat.