Go Down

Topic: How can we measure the amount of RAM consumed by a code in Arduino Due (Read 1 time) previous topic - next topic


I need to measure the amount of RAM used up by my code on Due. Can anybody tell me how to do it.
Thanks in advance. :)


Have you got an answer yet.
There are ways to to do it with other Arduinos. Is it different than with DUE.


There are libraries/functions for the AVRs but I don't know if they have been ported to the SAM.

A quick and dirty way is to malloc() a single byte and get it's address, subtract that value from the max RAM address then subtract a fudge factor for the stack.

On LPCs you can get the SP as well and that's probably a option on the SAM, but you could also call a dummy function and get the address of a local variable to get an approx stack value. Or for that matter get the address of a local var in loop().

Rob Gray aka the GRAYnomad www.robgray.com


This seems to provide a good number on a Mega

Code: [Select]
void setup() {
  byte stack;
   long heap = (long)malloc(1);
   Serial.println ((long)&stack );
   Serial.println (heap);
   Serial.println ((long)&stack - heap);


No reason to believe it would not work on the Due.

Rob Gray aka the GRAYnomad www.robgray.com

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131