Measuring Memory Usage

Is there a way to find out how much memory is currently in use on the 3pi? It’s just I’m trying to debug and am wondering if the bug is arising from running out of memory but have no way of knowing if that is the case.

Nvm, just found the get_free_ram() function!

Got another question regarding the memory:

[code]int main(){
clear();
print(" ");
print_long(get_free_ram()); // prints 2010 on the lcd

while(1);

}[/code]

[code]const char welcome[] PROGMEM = “>g32>>c32”;

int main(){
play_from_program_space(welcome);

clear();
print(" ");
print_long(get_free_ram());  // prints 1967 on the lcd

while(1);

}[/code]

How come the second example uses RAM? Isn’t it supposed to be reading from flash?

Hello. In the second code example you posted, the song itself is stored in flash and read directly from there. However, by calling play_from_program_space, you are causing the compiler/linker to load the OrangutanBuzzer section of the Pololu USB AVR C/C++ Library. That section of the library defines some variables to keep track of its current state, so that uses up some RAM.

I am not sure how you are compiling your code, but you should be able to tell GCC to generate .map file, which you can use to see how much flash and RAM is being used, and what it is being used for. However, this will not show dynamically allocated memory (from malloc) and variables that are on the stack.

–David

[quote=“DavidEGrayson”]Hello. In the second code example you posted, the song itself is stored in flash and read directly from there. However, by calling play_from_program_space, you are causing the compiler/linker to load the OrangutanBuzzer section of the Pololu USB AVR C/C++ Library. That section of the library defines some variables to keep track of its current state, so that uses up some RAM.

I am not sure how you are compiling your code, but you should be able to tell GCC to generate .map file, which you can use to see how much flash and RAM is being used, and what it is being used for. However, this will not show dynamically allocated memory (from malloc) and variables that are on the stack.

–David[/quote]

Ah ok, makes sense. Thanks!