Free Memory on the 101

Hi,

Is there support for the Memory Library on the Intel Arduino 101. I am using this library :

McNight Memory Free. I've used it on Mega, Uno and Nano's, now I want to use it or an equivalent on the 101.

When I try and use it to discover the amount of SRAM left on the heap I get this

C:\Users\Owner\AppData\Local\Temp\arduino_build_501838\libraries\Memory\MemoryFree.c.o: In function `getFreeMemory':

C:\Program Files (x86)\Arduino\libraries\Memory/MemoryFree.c:39: undefined reference to `__brkval'

collect2.exe: error: ld returned 1 exit status

I want to measure how much heap space I have left, I am dynamically new'ing my memory with new, and ergo malloc (so no stack variables except the local pointer declared in the function, no globals or statics in data space), I only want to know how much is left for a malloc.

Thanks.

At a first glance, it appears that the MemoryFree library depends on two symbols being declared by the malloc() in your libc implementation (See MemoryFree.cpp, line 9;

   extern unsigned int __heap_start;
   extern void *__brkval;

The malloc provided by AVR libc declares __brkval, see it here: avr-libc-1.7.1/libc/stdlib/malloc.c - toolchain/avr-libc - Git at Google

But Arduino101 has no AVR cores, and sketches are compiled for the ARC core, using a different libc- unfortunately the implementation of malloc provided by this libc doesn't declare a __brkval symbol: https://github.com/foss-for-synopsys-dwc-arc-processors/glibc/blob/vineet-2.24/malloc/malloc.c

however-- the MemoryFree library looks pretty simple. May not be difficult to make it support Arduino101, too, now that you have the two malloc() sources :slight_smile:

I looked into this a bit more, and did an Arduino101/tinyTILE version of this :slight_smile:

Our memory layout is a bit different, so it won't work exactly the same, but the header file has the same name (MemoryFree.h) and declares the same function, freeMemory(), so it should work with existing sketches. Added two extra functions as well-- see the header file in that pull request for full details, but the gist is...

freeMemory(): returns the size in bytes of total free space in both the stack & heap
freeStack(): returns the size in bytes of total free space in the stack
freeHeap(): returns the size in bytes of total free space in the heap