Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I measure the total size of my global variables?

Tags:

c

embedded

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?

like image 880
bradtgmurray Avatar asked Feb 25 '10 23:02

bradtgmurray


1 Answers

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

like image 186
don Avatar answered Oct 19 '22 11:10

don