0

The Arduino IDE used to warn you when your sketch used too much memory. This warning now seems to have been removed. I compiled a sketch, and was surprised to see it use 175% of data memory...but not give me any explicit warning that this would be unstable, much less be physically unable to load onto the Arduino.

What are program and data memory usage levels that you should be concerned about? I seem to remember the best practice was to keep data memory under 80%. Is this still true? Is there any general rule for program memory?

5
  • 2
    I'm surprised it even compiled...
    – Majenko
    Commented Jun 5, 2017 at 16:38
  • It seems unlikely the linker would accept this, perhaps there's a broken configuration as it seems like the percentage is being calculated against something that mismatched the linker map - for example, link for one chip, compare against another. Commented Jun 5, 2017 at 17:03
  • @Majenko, Me too :)
    – Cerin
    Commented Jun 5, 2017 at 18:32
  • Had you selected the wrong board? Commented Jun 7, 2017 at 8:40
  • What version of the Arduino IDE are you using?
    – sa_leinad
    Commented Jun 14, 2017 at 1:00

2 Answers 2

1

The compiler can only report the amount of statically allocated (RAM) memory. Depending on what you are doing in your sketch the value may be important, or it may be completely meaningless.

Suffice it to say, the total of heap + stack + static must not exceed the memory of your MCU.

When it comes to the Flash memory you can go right up to 100%.

1
0

It's a tough question to answer as it depends on the rest of the sketch. You can safely use every single byte of memory as long as you're sure that's all you're using. The number that it spits out on compile doesn't tell you that. It just tells you about global and static variables really. If you've got a loop that doesn't call any functions then you only need to save a few bytes for the stack. But if you've got a function that creates a local array with 500 ints then you're not safe even if that number it spits out on compile is only 50%.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.