How to know how much free RAM after compilation?

At Arduino IDE, we can see the total used Flash memory. But how to know how much used and available RAM?

Thanks

At Arduino IDE, we can see the total used Flash memory. But how to know how much used and available RAM?

If you search around this forum you will probably find out the method. It involves locating some of the files created during compilation and using command line utility programs provided to get a ram usage utilization. However even that doesn't guarantee that you can't have a ram shortage problem as at run time the stack is pushing and popping stuff from ram and can overwrite ram if too much stack is being used, and this can't be determined at compile time.

Lefty

I found this reference: http://www.arduino.cc/playground/Code/AvailableMemory

It works at running time.

Usually the compilers give a very good hint about the available RAM. However, as already commented, there are some scenarios that cannot be predicted by the compiler, such as a loop where a local variable is created. The stack for these variables can go to infinity causing buffer overflow.

Anyways, I am still not satisfied with the running time option. Any additional hint?

Anyways, I am still not satisfied with the running time option.

Not satisfied in what way? Are you expecting a genie to pop out of the lamp when the Arduino runs out of memory?

I think on reply #12 and higher they discuss how to get the compiler sram usage information. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1224729260

Lefty

Lefty, thank your for sharing this info.

PaulS, I mean that “I am not satisfied” with not having this kind of support built-in at the compiler. That is it only. I am not referring to a method of avoiding buffer overflow with 100% of confidence. I did not mention it.

The majority of the compilers for CPUs and MCUs have this support to help the developer to have a hint about the RAM cost of its implementation. Normally, if you don’t have a bug in the program and you are not close to the RAM limit, you are in a secure zone. This is my conclusion after many years working with this kind of stuff (although I am new with Arduino environment). I am just trying to receive help or silence. The kind of answer PaulS sent never helps.

Since the compiler can't tell if you are going to call code recursively at run time, or what sensors will trigger what code to be executed, in what order. I'm not sure how you expect the compiler to know how large the stack is going to get to be.

There are compile-time things that use SRAM and run-time things that use SRAM. The compile can only tell you about the compile-time use of SRAM.

It has no way of know how your code is going to behave at run-time, so it can not tell you anything about run-time usage of SRAM.

I was trying to get you to explain your dis-satisfaction. Just saying that you are not happy is like saying "It didn't work", without explaining what didn't work and how you know it isn't working.

The comment may not have been strictly necessary, and I'm sorry you felt offended by it.