How to get free RAM size on the Due?

It seems that the "usual" way to get the amount of free RAM that I have always used, i.e.:

(int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval)

does not work on the Due. Any idea of a method that works on said board?

Does this help? Get Free Memory for Teensy 3.0
I believe that Teensy and Due use the same (or similar) malloc code...
(It seems to work on my Due...)

Mmmh... No, I get some errors compiling. I should mention, though, that I'm not using a real Due, but rather a Digistump DigiX board with its own core package, which doesn't seem to be up to par with the official Due core. I will have to dig a bit more into that. Thanks indeed.

Give this a try...

Results with empty loop:

Dynamic ram used: 0
Program static ram used 5068
Stack ram used 80
My guess at free mem: 93156

Size of int: 4, Size of uint: 4
Size of char: 1, Size of uchar: 1
Size of short: 2, Size of ushort: 2
Size of float: 4, Size of double: 8
Size of long: 4, Size of longlong: 8
Size of pointer (ptr_i): 4
Addr of pointer (ptr_i): 0x20087fb4
Value of i: 0xaa
Direction <-- to trainer
Start...
#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;

char* Text[] = {
  /* [0]  */  "Start...",
  /* [1]  */  "Sensor1 Count  0",
  /* [2]  */  "Sensor1 Count  1",
  /* [3]  */  "Sensor1 Count  2",
  /* [4]  */  "Sensor1 Count  3",
  /* [5]  */  "Sensor1 Count  4",
  /* [6]  */  "Sensor1 Count  5",
  /* [7]  */  "Sensor1 Count  6",
  /* [8]  */  "Sensor1 Count  7",
  /* [9]  */  "Sensor1 Count  8",
  /* [10] */  "Sensor1 Count  9",
  /* [11] */  "Sensor1 Count 10",
  /* [12] */  "Sensor1 Count 11",
  /* [13] */  "Sensor1 Count 12",
  /* [14] */  "Sensor1 Count 13",
  /* [15] */  "Sensor1 Count 14",
  /* [16] */  "Sensor1 Count 15",
  /* [17] */  "Sensor1 Count 16",
  /* [18] */  "Sensor1 Count 17",
  /* [19] */  "Sensor1 Count 18",
  /* [20] */  "Sensor1 Count 19",
  /* [21] */  "Sensor1 Count 20",
  /* [22] */  "Sensor2 Count  0",
  /* [23] */  "Sensor2 Count  1",
  /* [24] */  "Sensor2 Count  2",
  /* [25] */  "Sensor2 Count  3",
  /* [26] */  "Sensor2 Count  4",
  /* [27] */  "Sensor2 Count  5",
  /* [28] */  "Sensor2 Count  6",
  /* [29] */  "Sensor2 Count  7",
  /* [30] */  "Sensor2 Count  8",
  /* [31] */  "Sensor2 Count  9",
  /* [32] */  "Sensor2 Count 10",
  /* [33] */  "Sensor2 Count 11",
  /* [34] */  "Sensor2 Count 12",
  /* [35] */  "Sensor2 Count 13",
  /* [36] */  "Sensor2 Count 14",
  /* [37] */  "Sensor2 Count 15",
  /* [38] */  "Sensor2 Count 16",
  /* [39] */  "Sensor2 Count 17",
  /* [40] */  "Sensor2 Count 18",
  /* [41] */  "Sensor2 Count 19",
  /* [42] */  "Sensor2 Count 20",
  /* [43] */  "Direction --> to box",
  /* [44] */  "Direction <-- to trainer",
  /* [45] */  "Nose to Nose",
  /* [46] */  "Fault",
  /* [47] */  "Race Completed",
  /* [48] */  "Error 1",
  /* [49] */  "Error 2",
  /* [50] */  "Error Unknown",
};


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);


Serial.println(Text[44]);
Serial.println(Text[0]);

}

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

Here's what I use. Seems to work fine:

void ShowMemory(void)
{
	struct mallinfo mi=mallinfo();

	char *heapend=sbrk(0);
	register char * stack_ptr asm("sp");

	pConsole->printf("    arena=%d\n",mi.arena);
	pConsole->printf("  ordblks=%d\n",mi.ordblks);
	pConsole->printf(" uordblks=%d\n",mi.uordblks);
	pConsole->printf(" fordblks=%d\n",mi.fordblks);
	pConsole->printf(" keepcost=%d\n",mi.keepcost);
	
	pConsole->printf("RAM Start %lx\n", (unsigned long)ramstart);
	pConsole->printf("Data/Bss end %lx\n", (unsigned long)&_end);
	pConsole->printf("Heap End %lx\n", (unsigned long)heapend);
	pConsole->printf("Stack Ptr %lx\n",(unsigned long)stack_ptr);
	pConsole->printf("RAM End %lx\n", (unsigned long)ramend);

	pConsole->printf("Heap RAM Used: %d\n",mi.uordblks);
	pConsole->printf("Program RAM Used %d\n",&_end - ramstart);
	pConsole->printf("Stack RAM Used %d\n",ramend - stack_ptr);

	pConsole->printf("Estimated Free RAM: %d\n\n",stack_ptr - heapend + mi.fordblks);
}

Regards,
Ray L.

Sorry for the delay, been busy.

I have just tried @RayLivingston's method and it looks fine.

Thanks!