|
| 1 | +## MemoryFree library for Arduino/Genuino101 and tinyTILE |
| 2 | + |
| 3 | +This library is a re-write of http://playground.arduino.cc/Code/AvailableMemory |
| 4 | +specifically for Curie-based devices. This library defines the same header file |
| 5 | +`MemoryFree.h`, and provides the function `freeMemory()`. In addition, two extra |
| 6 | +functions are provided; `freeHeap()`, for heap space only, and `freeStack()`, |
| 7 | +for free stack space. `freeStack()` can also be used to detect a stack overflow. |
| 8 | + |
| 9 | +The rewrite is necessary for two reasons: |
| 10 | + |
| 11 | +* AVR-based boards use a different implementation of `malloc()` than Curie-based |
| 12 | + boards, and in order to determine the amount of free heap space, we depend |
| 13 | + on specific symbols defined by the `malloc()` implementation. The `malloc()` |
| 14 | + implementation used by Curie-based devices |
| 15 | + [can be seen here](https://github.com/foss-for-synopsys-dwc-arc-processors/glibc). |
| 16 | + |
| 17 | +* Curie-based boards have a different memory layout than AVR-based boards. See |
| 18 | + the [linker script](https://github.com/01org/corelibs-arduino101/blob/master/variants/arduino_101/linker_scripts/flash.ld) |
| 19 | + for Arduino/Genuino 101 for details of the memory layout |
| 20 | + for Curie-based devices. |
| 21 | + |
| 22 | +## Functions |
| 23 | + |
| 24 | + |
| 25 | +`int freeHeap (void)` |
| 26 | + |
| 27 | +Returns the number of bytes free in the heap, i.e. the number of bytes free |
| 28 | +to be allocated using `malloc()`. |
| 29 | + |
| 30 | +`int freeStack (void)` |
| 31 | + |
| 32 | +Returns the number of bytes free in the stack, i.e. the space between the |
| 33 | +current stack frame and the end of the stack area. This function will return |
| 34 | +a negative number in the event of a stack overflow, representing the size of |
| 35 | +the overflow; for example, a return value of -20 means that the current stack |
| 36 | +frame is 20 bytes past the end of the stack area. |
| 37 | + |
| 38 | +`int freeMemory (void)` |
| 39 | + |
| 40 | +Returns the number of bytes free in both the stack and the heap. If a stack |
| 41 | +overflow has occurred, only the number of bytes free in the heap is returned. |
0 commit comments