1

I use this Library to measure my free RAM on a Mega in runtime. But this Library does not work on the Due.

asked Oct 24, 2016 at 14:12
1

2 Answers 2

1

As mentioned by Mikael Patel in a comment, the library from Arduino-MemoryFree should do it. A minimal sketch that seems to work on the Due:

extern "C" char* sbrk(int incr);
int freeMemory() {
 char top;
 return &top - reinterpret_cast<char*>(sbrk(0));
}
void setup ()
{
 Serial.begin (115200);
 Serial.println ();
 Serial.print ("Free memory is: ");
 Serial.println (freeMemory ());
} // end of setup
void loop () { }

I'm not totally convinced that this gives the correct figure. The figure returned by the library above for my Uno was too high (2297 bytes).

answered Oct 25, 2016 at 8:54
2
  • It seems to work fine after a call to malloc(), which is needed to initialize __brkval. I would return &top - ( __brkval ? __brkval : &__heap_start); in order to have something that works also when not using malloc(). Commented Oct 25, 2016 at 9:34
  • I thought it might be something like that. After all, not everyone uses malloc. Commented Oct 25, 2016 at 10:50
0

Try to use this method:

int freeRAM() {
 extern int __heap_start, *__brkval;
 int v;
 return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
answered Oct 25, 2016 at 4:12
1
  • 1
    The question was about a Due. When I tried your code on my Due I got -28 bytes of RAM, which is hard to believe. Commented Oct 25, 2016 at 8:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.