Arduino Available Memory Test
I’ve been meaning to make a nice little function to test available memory for some time, so tonight in response to a mailing list question, I went ahead and created an Arduino Available RAM Test for exploring memory allocation.
While I’m still learning about AVR’s memory management, here’s what I understand so far: The ATMEGA8 has 8K of program memory but only 1K of RAM. (Program memory is for code and RAM is for dynamic variables.) Actually it’s effectively less than 1K of RAM, I think because the Arduino libraries take up some dynamic memory space for themselves. The ATMEGA168 increases program memory to 16K, but RAM remains unchanged at 1K.
The Arduino environment will happily let you compile a program that exceeds the microcontroller’s RAM limits, however program behavior will become totally unpredictable, the code will do bizarre things and/or crash. It is equally difficult to describe the negative emotional results for the coder. Dysphoria comes to mind.
Hopefully, the Arduino Available RAM Test code can provide a pathway back to happiness, or at least cathartic understanding.