I'm creating a c program that I intend to run on an ARM processor in the near timeframe. I want to measure the amount of memory I'm using with my global variables while ignoring the size of the stack/heap. Is there a way to either get gcc to dump this out at compile time or to retrieve this information from the compiled binary?
A great way to see where your memory is going is to look at the linker map. A linker map is a file that is generated by the linker and details all memory locations for the program. You can see memory allocation on a symbol by symbol basis for global variables as well as code. I've used linker maps in the past for projects which have tight memory requirements. They make it easy to identify problems areas like global memory buffers which take up alot of space.
Add this option to the gcc command line to generate the linker map:
-Wl,-Map=output.map
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With