Due RAM Usage

When doing a compile with an AVR-based Arduino, an estimated RAM usage is displayed. This doesn't happen when doing Due compiles. Is there an easy way to gauge RAM usage?

Regards,
Ray L.

Some code I've picked up from somewhere and previously tried ... not sure how accurate it is though:

#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>

extern char _end;
extern "C" char *sbrk(int i);
char *ramstart = (char *)0x20070000;
char *ramend = (char *)0x20088000;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  char *heapend = sbrk(0);
  register char * stack_ptr asm ("sp");
  struct mallinfo mi = mallinfo();
  printf("\nDynamic ram used: %d\n", mi.uordblks);
  printf("Program static ram used %d\n", &_end - ramstart);
  printf("Stack ram used %d\n", ramend - stack_ptr);
  printf("My guess at free mem: %d\n\n", stack_ptr - heapend + mi.fordblks);

  int* ptr_i;
  int i = 0xaa;
  ptr_i = &i;

  printf("Size of int: %d, Size of uint: %d\n", sizeof(int), sizeof(unsigned int));
  printf("Size of char: %d, Size of uchar: %d\n", sizeof(char), sizeof(unsigned char));
  printf("Size of short: %d, Size of ushort: %d\n", sizeof(short), sizeof(unsigned short));
  printf("Size of float: %d, Size of double: %d\n", sizeof(float), sizeof(double));
  printf("Size of long: %d, Size of longlong: %d\n", sizeof(long), sizeof(long long));
  printf("Size of pointer (ptr_i): %d\n", sizeof(ptr_i));
  printf("Addr of pointer (ptr_i): 0x%x\n", ptr_i);
  printf("Value of i: 0x%x\n", *ptr_i);
}

void loop() {
  // put your main code here, to run repeatedly:
}

dlloyd:
Some code I've picked up from somewhere and previously tried ... not sure how accurate it is though:

#include <malloc.h>

#include <stdlib.h>
#include <stdio.h>

extern char _end;
extern "C" char *sbrk(int i);
char *ramstart = (char *)0x20070000;
char *ramend = (char *)0x20088000;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  char *heapend = sbrk(0);
  register char * stack_ptr asm ("sp");
  struct mallinfo mi = mallinfo();
  printf("\nDynamic ram used: %d\n", mi.uordblks);
  printf("Program static ram used %d\n", &_end - ramstart);
  printf("Stack ram used %d\n", ramend - stack_ptr);
  printf("My guess at free mem: %d\n\n", stack_ptr - heapend + mi.fordblks);

int* ptr_i;
  int i = 0xaa;
  ptr_i = &i;

printf("Size of int: %d, Size of uint: %d\n", sizeof(int), sizeof(unsigned int));
  printf("Size of char: %d, Size of uchar: %d\n", sizeof(char), sizeof(unsigned char));
  printf("Size of short: %d, Size of ushort: %d\n", sizeof(short), sizeof(unsigned short));
  printf("Size of float: %d, Size of double: %d\n", sizeof(float), sizeof(double));
  printf("Size of long: %d, Size of longlong: %d\n", sizeof(long), sizeof(long long));
  printf("Size of pointer (ptr_i): %d\n", sizeof(ptr_i));
  printf("Addr of pointer (ptr_i): 0x%x\n", ptr_i);
  printf("Value of i: 0x%x\n", *ptr_i);
}

void loop() {
  // put your main code here, to run repeatedly:
}

Thanks! I'll give that a try and let you know what I get.

Regards,
Ray L.