This project has moved. For the latest updates, please go here.
The members of MemoryInformation return the size (in bytes) of different memory sections


#include <MemoryInformation.h>

void setup() { 

//Create MemoryInformation class
MemoryInformation memInfo=MemoryInformation();

void loop() {
  //If you want to display all values at once, sent it directly to print() or println():
  //Or you access each member:
  Serial.print(F("DATA section: "));
  Serial.println( memInfo.dataSize() );  
  Serial.print(F("BSS section: "));
  Serial.println( memInfo.bssSize() );  
  Serial.print(F("Heap size: "));
  Serial.println( memInfo.heapSize() );  
  Serial.print(F("Free memory: "));
  Serial.println( memInfo.freeMemorySize() );

  Serial.print(F("Stack size: "));
  Serial.println( memInfo.stackSize() );

  Serial.print(F("RAM Total Size: "));
  Serial.println( memInfo.ramSize() );
  //Refresh memory information


This class can aid in debugging, if you want to know how the memory on your Arduino is currently organized. In case you just want to know how many free memory your board currently has, use availableMemory() in AvailableMemory.h.

If you just want to know how the memory is currently organized, just sent the class instance to Serial: Serial.println(memInfo);. To know how big the different sections are use the corresponding function like this int i=memInfo.heapSize();. The data can be refreshed at any time by calling memInfo.refresh();.

The memory on a ATmega CPUs is divided into several parts: DATA and BSS are static, they do not change when executing your sketch. Heap is used every time you need memory, and Stack is used when one function calls another (e.g. you call pinMode(13, OUTPUT) from inside the loop() function). Between them the free memory is located. Note also that Heap grows towards the free memory section, while Stack grows downward (as indicated by the arrows).

  | DATA     | BSS      |  Heap  |     FREE     |  Stack |
  | (Static) | (Static) |  --->  |     MEM      |  <---  |

For a much better description about this topic, please see "Jean-Claude Wippler: ATmega memory use"


Smilen Dimitrov: Corrupt Array Variables And Memory

The general calculation code was published by Marc Compere in this forum post (Please be warned that the calculation is incorrect if __brkval is 0):,27536.msg204023.html#msg204023

AVR Malloc Manual:

Andy Brown: Debugging AVR dynamic memory allocation

Last edited Oct 19, 2012 at 9:59 AM by TeXHeX, version 14


No comments yet.