List of Variables and memory space/usage

This may be in the wrong category, since it has nothing to do with programming.
Didn't know where to put it though

Q1.
Can i get a list all my variables somehow? I'm not interested in their values, just a list of their names, sizes and storage locations
I'm using Arduino Mega + Visual Studio+Visual Micro and/or Arduino 1.5.5 IDE

Reason:
I'm working on a BIG project, with a sketch that takes up 77% (6336B) of data memory.
I'm aware of the problems with heap-stack collition and suspect having some memory problems due to some strange behaivior in the program

I've done my best in decreasing the datatype sizes to a minimum and also to to reuse, or use local variables as much as possible.
All my constant textstrings are placed in program memomy, with F() or other way.

I would now like to list everything placed inte the Data memory, to see what and how much space everything takes, in order to make more shrinking.
Q2.
Any other ideas on how to save more data memory? I've tried my best in not using String variables.

Q3. Tried a little experiment. I declared a couple of
char xxx[1500] = "kalkdfjsdafjaskfjksflskj....... - - - ..dadadadadad";
With alot of charachters, multiplied by 10 copys with different names.
These were places globally.
When compiling, both the data & program memory are exactly the same as before. Where're all these string stored????

Thanx.

also... whenever i used String, i've also done a reservation for minimizing memory fragmantation problems.

Don't know if this matters in this case, but i wanted to mention it

For example:
String myStr;
myStr.reserve(10);

You can examine the contents of an object (or elf) file using the avr-objdump command. Best bet is to use the .elf file (in the build folder). For example (under linux):

$ avr-objdump -t Blink.elf

Blink.elf:     file format elf32-avr

SYMBOL TABLE:
00800100 l    d  .data	00000000 .data
00000000 l    d  .text	00000000 .text
00800102 l    d  .bss	00000000 .bss
00000000 l    d  .stab	00000000 .stab
00000000 l    d  .stabstr	00000000 .stabstr
00000000 l    df *ABS*	00000000 Blink.cpp
0000003f l       *ABS*	00000000 __SREG__
0000003e l       *ABS*	00000000 __SP_H__
0000003d l       *ABS*	00000000 __SP_L__
00000034 l       *ABS*	00000000 __CCP__
00000000 l       *ABS*	00000000 __tmp_reg__
00000001 l       *ABS*	00000000 __zero_reg__
00000000 l    df *ABS*	00000000 wiring_digital.c
0000003f l       *ABS*	00000000 __SREG__
0000003e l       *ABS*	00000000 __SP_H__
0000003d l       *ABS*	00000000 __SP_L__
00000034 l       *ABS*	00000000 __CCP__
00000000 l       *ABS*	00000000 __tmp_reg__
00000001 l       *ABS*	00000000 __zero_reg__
000000de l       .text	00000000 .do_copy_data_start
000000da l       .text	00000000 .do_copy_data_loop
000000ee l       .text	00000000 .do_clear_bss_start
000000ec l       .text	00000000 .do_clear_bss_loop
00000000 l    df *ABS*	00000000 wiring.c
0000003f l       *ABS*	00000000 __SREG__
0000003e l       *ABS*	00000000 __SP_H__
0000003d l       *ABS*	00000000 __SP_L__
00000034 l       *ABS*	00000000 __CCP__
00000000 l       *ABS*	00000000 __tmp_reg__
00000001 l       *ABS*	00000000 __zero_reg__
0080010a l     O .bss	00000001 timer0_fract
00000000 l    df *ABS*	00000000 main.cpp
0000003f l       *ABS*	00000000 __SREG__
0000003e l       *ABS*	00000000 __SP_H__
0000003d l       *ABS*	00000000 __SP_L__
00000034 l       *ABS*	00000000 __CCP__
00000000 l       *ABS*	00000000 __tmp_reg__
00000001 l       *ABS*	00000000 __zero_reg__
00000438 l       .text	00000000 __stop_program
000000fc  w      .text	00000000 __vector_22
00800102 g     O .bss	00000004 timer0_overflow_count
00000068 g     O .text	0000000a port_to_mode_PGM
000000fc  w      .text	00000000 __vector_1
00800106 g     O .bss	00000004 timer0_millis
000000c2 g       .text	00000000 __trampolines_start
0000043a g       .text	00000000 _etext
000000fc  w      .text	00000000 __vector_24
00000100 g     F .text	0000002e loop
000000fc  w      .text	00000000 __vector_12
000000fc g       .text	00000000 __bad_interrupt
0000043c g       *ABS*	00000000 __data_load_end
000000fc  w      .text	00000000 __vector_6
000000c2 g       .text	00000000 __trampolines_end
000000fc  w      .text	00000000 __vector_3
000001b8 g     F .text	000000a8 digitalWrite
0000013a g     F .text	0000007e pinMode
00000086 g     O .text	00000014 digital_pin_to_port_PGM
000000fc  w      .text	00000000 __vector_23
0000043a g       *ABS*	00000000 __data_load_start
000000c2 g       .text	00000000 __dtors_end
0080010b g       .bss	00000000 __bss_end
000000fc  w      .text	00000000 __vector_25
000000fc  w      .text	00000000 __vector_11
000000c2  w      .text	00000000 __init
00000000  w      *UND*	00000000 _Z14serialEventRunv
000000fc  w      .text	00000000 __vector_13
00800100 g     O .data	00000002 led
000000fc  w      .text	00000000 __vector_17
000000fc  w      .text	00000000 __vector_19
000000fc  w      .text	00000000 __vector_7
000000e4 g       .text	00000000 __do_clear_bss
00810000 g       .stab	00000000 __eeprom_end
0000009a g     O .text	00000014 digital_pin_to_bit_mask_PGM
00000000 g       .text	00000000 __vectors
00800102 g       .data	00000000 __data_end
00000000  w      .text	00000000 __vector_default
000000fc  w      .text	00000000 __vector_5
000003a2 g     F .text	00000076 init
000000c2 g       .text	00000000 __ctors_start
000000ce g       .text	00000000 __do_copy_data
00800102 g       .bss	00000000 __bss_start
00000418  w    F .text	0000001e main
000000fc  w      .text	00000000 __vector_4
00000000  w      *ABS*	00000000 __heap_end
000000fc  w      .text	00000000 __vector_9
000002f0 g     F .text	000000b2 delay
000000fc  w      .text	00000000 __vector_2
000000fc  w      .text	00000000 __vector_21
000000fc  w      .text	00000000 __vector_15
00000072 g     O .text	0000000a port_to_output_PGM
0000012e g     F .text	0000000c setup
000000c2 g       .text	00000000 __dtors_start
000000c2 g       .text	00000000 __ctors_end
000008ff  w      *ABS*	00000000 __stack
0000007c g     O .text	0000000a port_to_input_PGM
00800102 g       .data	00000000 _edata
0080010b g       .stab	00000000 _end
000000fc  w      .text	00000000 __vector_8
000000ae g     O .text	00000014 digital_pin_to_timer_PGM
00000436  w      .text	00000000 exit
00000436 g       .text	00000000 _exit
000000fc  w      .text	00000000 __vector_14
000000fc  w      .text	00000000 __vector_10
00000260 g     F .text	00000090 __vector_16
00800100 g       .data	00000000 __data_start
000000fc  w      .text	00000000 __vector_18
000000fc  w      .text	00000000 __vector_20

The lines you're interested in are .data and .bss lines. First number is the location, second is the number of bytes.

The command would be the same under Windows, but you'd have to find where the command is stored and point to it.

Thanx alot. Great answer!!!

I did manage to extract all this data and import it to Excel for analyzing.

some things striked me:

  1. If i sum up all the datalength for variables in .bss and .data, it sums up to approx 1277Bytes. According to the compiler, i've used 5438Bytes. What else is stored in the data-area (SRAM)?

  2. i also noticed that Serial1, Serial2...Serial4 takes up 162Bytes. Is that the buffers, or what? As i recall, my buffer-sizes are at 64Bytes.

  3. i notice thar Booleans take up 1Byte, wasting 7bits per variable.

For windows users that want to do tihs, avr-objdump is located in the Arduino install folder/hardware/tools/avr/bin

  1. i notice thar Booleans take up 1Byte, wasting 7bits per variable.

As soon as you have a 1 bit machine, you can have a 1 bit boolean variable.

In the mean time, you can roll your own with a byte array and some functions to allow you to set and test indvidual bytes.

KeithRB:

  1. i notice thar Booleans take up 1Byte, wasting 7bits per variable.

As soon as you have a 1 bit machine, you can have a 1 bit boolean variable.

In the mean time, you can roll your own with a byte array and some functions to allow you to set and test indvidual bytes.

You have a good point Sir.
I thought, maybe, the compiler is so smart that it boundles a bunch of booleans together, to save memory area. But apparently, it doesn't.

I thought, maybe, the compiler is so smart that it boundles a bunch of booleans together, to save memory area. But apparently, it doesn't.

It isn't a question of how smart it is, it is a question of what it is allowed to do.

In C/C++, you can't return the address of a bit, so a bit is not a valid candidate for storing a named data item.

The compiler can do that if you tell it to, look up bit fields, and promptly forget them.