Go Down

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

sohini25

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. :)

LMI

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

Graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

Graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

Go Up