0

I have the following output of my sketch for the Arduino Mega so far:

Sketch uses 25020 bytes (9%) of program storage space. Maximum is 253952 bytes.
Global variables use 6919 bytes (84%) of dynamic memory, leaving 1273 bytes for
local variables. Maximum is 8192 bytes.

Low memory available, stability problems may occur.

I think 1273 bytes is not so less for most sketches, although mine is quite big (several thousand of lines, and I'm about half).

I was wondering if the IDE is so smart to statically analyze my code to see what my dynamic storage is (about 600 bytes) and/or calculates some expected stack size (several hundred bytes at least).

Or is it just a (very) safe fixed or percentage-based value?

  • 1273 = 8192 - 6919. There is no guessing whatsoever on the part of the IDE. – Edgar Bonet Jul 20 at 21:47
  • What I mean is, why it gives already a warning when I still have 1273 bytes left? It seems like a 'very safe' value. – Michel Keijzers Jul 20 at 21:49
1

I just did some tests and found the answer.

char a[6135];

void setup() 
{
  a[0] = 0;
}

void loop() 
{
}

This sketch does not give a warning:

Sketch uses 660 bytes (0%) of program storage space. Maximum is 253952 bytes.
Global variables use 6144 bytes (75%) of dynamic memory, leaving 2048 bytes for local variables. Maximum is 8192 bytes.

If I increase the array with 1, I get an error:

Sketch uses 660 bytes (0%) of program storage space. Maximum is 253952 bytes.
Global variables use 6145 bytes (75%) of dynamic memory, leaving 2047 bytes for local variables. Maximum is 8192 bytes.
Low memory available, stability problems may occur.

Conclusion: below 2 KB (2048 bytes) of free space, the warning is shown.

I did the same test for the Uno, and there the warning is shown when less than 1536 bytes are free.

Both percentages are 75%, so the end conclusion is that the value is based on 75% of memory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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