MemoryUsage
Arduino library MemoryUsage
|
A full explanation in french can be read at http://www.locoduino.org/ecrire/?exec=article&action=redirect&type=article&id=149 .
Roughly, the SRAM memory is divided into four areas: the static data, the heap, the free ram and the stack.
The static data size is given by the compiler itself after the building. this is filled by all variables and arrays declared in global scope, or with 'static' keyword.
The heap is filled with all the dynamic allocations done with 'new' keyword or 'malloc' functions.
The stack start from the end of the SRAM area and grow and shrink downward at each function call, it stores all the local data internal to a function, function arguments (depending of the architecture, arguments can be stored in CPU registers to improve speed...) , and addresses for function returns to caller.
SRAM memory
+---------------+------------------+---------------------------------------------+-----------------+ | | | | | | | | | | | static | | | | | data | heap | free ram | stack | | | | | | | | | | | | | | | | +---------------+------------------+---------------------------------------------+-----------------+ _end or __heap_start __brkval SP RAMEND
Source : http://www.nongnu.org/avr-libc/user-manual/malloc.html
MemoryUsage try to help you to find the actual memory status with differents strategies, but dont forget that when you observe something, you change the result of the observation : execution time is consumed by the analysis tools, and memory used will grow because of these tools !
#include <MemoryUsage.h> STACK_DECLARE void setup() ...
then add a STACK_COMPUTE in any function that can be called :
void subFonction() { double v[SIZE]; STACK_COMPUTE; .... // do things }
and finish by printing on the console the biggest size of the stack with STACK_PRINT or STACK_PRINT_TEXT. Be careful with this method, this introduce some code in every function of your sketch, so if the timing is important for your applicaion, take care of it !