How much free memory ?

Is there a simple way I can get the amount of free memory using a library call ?

Andy

http://www.arduino.cc/playground/Code/AvailableMemory
Is a start.

Thanks,

just what I needed !

Andy

:frowning:

Why the face, Mike?
Honestly, it's like living with teenagers around here, sometimes :smiley:

I agree… >:( … none of the above are good solutions.

Here is my solution, which is based on the code in malloc.c that checks for enough available memory. This is from the AVR-LIBC 1.6.6 distribution but may well work with earlier versions if the code hasn’t changed.

#include <stdlib.h>
#include <inttypes.h>
#include <avr/io.h>

extern char * const __brkval;

uint16_t freeMem(void)
{
  char *brkval;
  char *cp;

  brkval = __brkval;
  if (brkval == 0) {
    brkval = __malloc_heap_start;
  }
  cp = __malloc_heap_end;
  if (cp == 0) {
    cp = ((char *)AVR_STACK_POINTER_REG) - __malloc_margin;
  }
  if (cp <= brkval) return 0;

  return cp - brkval;
}

Thanks for the better code. I really only needed a function for debugging, checking for memory leaks.

But thanks again all.

Andy