More verbose of global variables

Hi everybody,

I'm using ATTINY84, and one problem is the size of the SRAM. The other problem is that ATTINY84 will not be produced anymore, but ... arduino forum can't help for that.

Actually, my sketch give me that information :

Sketch uses 6962 bytes (84%) of program storage space. Maximum is 8192 bytes.
Global variables use 359 bytes (70%) of dynamic memory, leaving 153 bytes for local variables. Maximum is 512 bytes.

if i count all "global" var, i get ~300B of memory used, but i dont get where is used the 59B others. Maybe from the arduino library like arduino.h but i don't know.
I tried googling information about memory usage, but most of case, i get memory usage on running arduino, but can't get information from the compiler.

Is there a way to get it ? Like a list :
var1 - 1B
var2 - 4B
...

Thanks in advance,

Please post your sketch, using code tags when you do

you could probably use avr-objdump on the elf file to explore the various segments

To show all symbols and their size, including code:

~/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-nm -CS --size-sort /tmp/arduino/sketches/B1641B74DD848AF05EB60E79C4564EA7/Blink.ino.elf

To show only variables in the .bss and .data sections:

~/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-nm -CS --size-sort /tmp/arduino/sketches/B1641B74DD848AF05EB60E79C4564EA7/Blink.ino.elf | grep ' [dDbB] '

Alternatively, use objdump:

~/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objdump -Ct -j .bss -j .data /tmp/arduino/sketches/B1641B74DD848AF05EB60E79C4564EA7/Blink.ino.elf

Note that this won't show any string literals that may be taking up RAM.

Ok, thanks for ur replies.

If i understand the output, it uses memory for all function definition for example :

00000598 00000076 t digitalWrite        [...]\Arduino15\packages\ATTinyCore\hardware\avr\1.5.2\cores\tiny/wiring_digital.c:136

If yes, i thought that it use stack for that, so it would be dynamic allocation.

Sure, but functions are not loaded into RAM on AVR, they appear in flash only.

No, the stack is used for local variables, saved registers, and function return addresses. Not for the functions themselves.

Some architectures do support having functions in RAM (e.g. your x86 or ARM PC, ESP32 and ARM microcontrollers, etc.), but AVR is based on a Harvard architecture, which separates code and data, so it cannot execute code from RAM.

For goodness sake, please post your sketch so that we can see what you are doing

Sorry, i wanted to say that it allocated RAM for var which are passed on parameter. It's what i understand when it use memory for function.

For example, with :
func(uint8_t var1, uint8_t var2)

it will keep 2B of memory for var1 & var2. Or it use RAM for something else ?

I don't get the point, this is general asking

It won’t reserve memory at compile time. The parameters will be allocated on the stack at run time

So why do i get RAM usage for function ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.