FYI,
I have been programming my Arduino Mega 2560 for some time now. My largest program is over 100 kb. The biggest problem that I had was memory availability. Due to the many functions used and the many different sequence of events, I found it extremely difficult to determine if I would run out of memory at some point. My program was designed to run continuously for very long periods of time.
The only way I found to feel comfortable that I would not run out of memory was the following:
-
After the program loads, I determine the start and end of the initially available RAM.
-
I then fill this area of memory with a known pattern of data (Ex. QWERTYQWERTYQWERTY...)
-
When a function begins or ends, I find the beginning and end of my pattern.
-
The number of bytes containing my pattern, gives me the minimum amount of memory that was available.
-
I log this amount to a file on the SD card and can also view this by sending a request to the Arduino.
I hope this helps someone out there as it did for me.
Nick Amendola