Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Tool for static analysis of memory usage

Tool for static analysis of memory usage

Scheduled Pinned Locked Moved Development
8 Posts 2 Posters 2.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mfalkviddM Offline
    mfalkviddM Offline
    mfalkvidd
    Mod
    wrote on last edited by
    #1

    The Arduino IDE tells me how much ram will be used by global variables, like this:

    Global variables use 2,412 bytes (117%) of dynamic memory, leaving -364 bytes for local variables. Maximum is 2,048 bytes.
    

    Is there a tool that can tell me which global variables use the most memory? Or just a list of all variables and their sizes? The tools I've been able to find (valgrind for example) focus on dynamic analysis.

    I want to find out which variables use a lot of memory, so I can see where I should spend effort to optimize. This is a large project, which uses several libraries, so looking through them by hand is cumbersome.

    TheoLT 1 Reply Last reply
    1
    • mfalkviddM mfalkvidd

      The Arduino IDE tells me how much ram will be used by global variables, like this:

      Global variables use 2,412 bytes (117%) of dynamic memory, leaving -364 bytes for local variables. Maximum is 2,048 bytes.
      

      Is there a tool that can tell me which global variables use the most memory? Or just a list of all variables and their sizes? The tools I've been able to find (valgrind for example) focus on dynamic analysis.

      I want to find out which variables use a lot of memory, so I can see where I should spend effort to optimize. This is a large project, which uses several libraries, so looking through them by hand is cumbersome.

      TheoLT Offline
      TheoLT Offline
      TheoL
      Contest Winner
      wrote on last edited by TheoL
      #2

      @mfalkvidd I'm interested too. Also I'm wondering what else goes into that memory space? I sometimes get the feeling that's some kind of heap space. It seems like the more functions I use the more memory is used as well.

      And I would love it if they just would add a decent refactor support in the IDE

      1 Reply Last reply
      0
      • mfalkviddM Offline
        mfalkviddM Offline
        mfalkvidd
        Mod
        wrote on last edited by mfalkvidd
        #3

        AdaFruit has a great guide on Arduino memory https://learn.adafruit.com/memories-of-an-arduino/

        Good example on how to use PROGMEM: http://www.codeproject.com/Articles/1013667/Optimize-Arduino-Memory-Usage

        But to use these guides, I first need to find where to focus my effort.

        avr-size can display some information:

        avr-size.exe -A R:\Scratch\Tetris.ino.elf
        R:\Scratch\Tetris.ino.elf  :
        section            size      addr
        .data              1360   8388864
        .text             19020         0
        .bss               1124   8390224
        .comment             17         0
        .debug_aranges     2032         0
        .debug_info      176644         0
        .debug_abbrev     18445         0
        .debug_line       23110         0
        .debug_frame       9696         0
        .debug_str        27466         0
        .debug_loc       104530         0
        .debug_ranges      3480         0
        Total            386924
        

        But the best so far is readelf (header added manually for clarity):

        avr-readelf.exe -a 'r:\Scratch\Tetris.ino.elf' | less | grep OBJECT | sort -nk3 | head
           Num:    Value  Size Type    Bind   Vis      Ndx Name
            24: 0080038d   676 OBJECT  LOCAL  DEFAULT    1 _ZL15MatriseFontData
           282: 008008d2   445 OBJECT  GLOBAL DEFAULT    3 leds
           255: 00800752   144 OBJECT  GLOBAL DEFAULT    3 AttractMsg
           258: 008006fa    88 OBJECT  GLOBAL DEFAULT    3 GameOverMsg
           209: 00800875    72 OBJECT  GLOBAL DEFAULT    3 PlayfieldData
            45: 0080035d    48 OBJECT  LOCAL  DEFAULT    1 _ZL11TetrisIData
            43: 0080031d    48 OBJECT  LOCAL  DEFAULT    1 _ZL11TetrisJData
            41: 008002dd    48 OBJECT  LOCAL  DEFAULT    1 _ZL11TetrisLData
            39: 0080029d    48 OBJECT  LOCAL  DEFAULT    1 _ZL11TetrisOData
            37: 0080025d    48 OBJECT  LOCAL  DEFAULT    1 _ZL11TetrisSData
        

        So the real memory hogs in my case seems to be Font Data and the 144 pixel led array, which can be expected to be large. After that comes three long strings. I'll see if I can move the font and the strings to PROGMEM or apply some other tweak.

        TheoLT 1 Reply Last reply
        1
        • mfalkviddM mfalkvidd

          AdaFruit has a great guide on Arduino memory https://learn.adafruit.com/memories-of-an-arduino/

          Good example on how to use PROGMEM: http://www.codeproject.com/Articles/1013667/Optimize-Arduino-Memory-Usage

          But to use these guides, I first need to find where to focus my effort.

          avr-size can display some information:

          avr-size.exe -A R:\Scratch\Tetris.ino.elf
          R:\Scratch\Tetris.ino.elf  :
          section            size      addr
          .data              1360   8388864
          .text             19020         0
          .bss               1124   8390224
          .comment             17         0
          .debug_aranges     2032         0
          .debug_info      176644         0
          .debug_abbrev     18445         0
          .debug_line       23110         0
          .debug_frame       9696         0
          .debug_str        27466         0
          .debug_loc       104530         0
          .debug_ranges      3480         0
          Total            386924
          

          But the best so far is readelf (header added manually for clarity):

          avr-readelf.exe -a 'r:\Scratch\Tetris.ino.elf' | less | grep OBJECT | sort -nk3 | head
             Num:    Value  Size Type    Bind   Vis      Ndx Name
              24: 0080038d   676 OBJECT  LOCAL  DEFAULT    1 _ZL15MatriseFontData
             282: 008008d2   445 OBJECT  GLOBAL DEFAULT    3 leds
             255: 00800752   144 OBJECT  GLOBAL DEFAULT    3 AttractMsg
             258: 008006fa    88 OBJECT  GLOBAL DEFAULT    3 GameOverMsg
             209: 00800875    72 OBJECT  GLOBAL DEFAULT    3 PlayfieldData
              45: 0080035d    48 OBJECT  LOCAL  DEFAULT    1 _ZL11TetrisIData
              43: 0080031d    48 OBJECT  LOCAL  DEFAULT    1 _ZL11TetrisJData
              41: 008002dd    48 OBJECT  LOCAL  DEFAULT    1 _ZL11TetrisLData
              39: 0080029d    48 OBJECT  LOCAL  DEFAULT    1 _ZL11TetrisOData
              37: 0080025d    48 OBJECT  LOCAL  DEFAULT    1 _ZL11TetrisSData
          

          So the real memory hogs in my case seems to be Font Data and the 144 pixel led array, which can be expected to be large. After that comes three long strings. I'll see if I can move the font and the strings to PROGMEM or apply some other tweak.

          TheoLT Offline
          TheoLT Offline
          TheoL
          Contest Winner
          wrote on last edited by
          #4

          @mfalkvidd that's an interesting project your working on...!

          mfalkviddM 1 Reply Last reply
          0
          • TheoLT TheoL

            @mfalkvidd that's an interesting project your working on...!

            mfalkviddM Offline
            mfalkviddM Offline
            mfalkvidd
            Mod
            wrote on last edited by mfalkvidd
            #5

            @TheoL yes, I think it might come out pretty cool. I have built a 22" 12x12 led matrix screen out of 5m ws2811 led strip, on which I plan to play Tetris.

            https://youtu.be/J23oHPLGn9E

            TheoLT 1 Reply Last reply
            3
            • mfalkviddM mfalkvidd

              @TheoL yes, I think it might come out pretty cool. I have built a 22" 12x12 led matrix screen out of 5m ws2811 led strip, on which I plan to play Tetris.

              https://youtu.be/J23oHPLGn9E

              TheoLT Offline
              TheoLT Offline
              TheoL
              Contest Winner
              wrote on last edited by
              #6

              @mfalkvidd I don't know what I like the most about that video. The matrix or the music. You've go a new subscriber.

              I'm almost done with my first i2c tinyAt 85 slave project. Was a p@1n in the butt. Will be an i2c remote receiver that you can add to your MySensors projects. It's hard to do the first time. But I'll be adding an tinyAT 85 i2c slave to all my Arduino projects where I need more memory.

              You could let the tinyAT 85 monitor the controls. Saves memory..

              mfalkviddM 1 Reply Last reply
              0
              • TheoLT TheoL

                @mfalkvidd I don't know what I like the most about that video. The matrix or the music. You've go a new subscriber.

                I'm almost done with my first i2c tinyAt 85 slave project. Was a p@1n in the butt. Will be an i2c remote receiver that you can add to your MySensors projects. It's hard to do the first time. But I'll be adding an tinyAT 85 i2c slave to all my Arduino projects where I need more memory.

                You could let the tinyAT 85 monitor the controls. Saves memory..

                mfalkviddM Offline
                mfalkviddM Offline
                mfalkvidd
                Mod
                wrote on last edited by mfalkvidd
                #7

                @TheoL thanks for the tip on AtTiny85. I happen to have 2 of them in my stash of mcu:s.

                For now I will probably just use a nodemcu/esp8266 esp-12. It has lots of ram:

                Sketch uses 235,469 bytes (22%) of program storage space. Maximum is 1,044,464 bytes.
                Global variables use 34,412 bytes (42%) of dynamic memory, leaving 47,508 bytes for local variables. Maximum is 81,920 bytes.
                

                I might use a separate node for the controller, communicating using the nrf.

                TheoLT 1 Reply Last reply
                0
                • mfalkviddM mfalkvidd

                  @TheoL thanks for the tip on AtTiny85. I happen to have 2 of them in my stash of mcu:s.

                  For now I will probably just use a nodemcu/esp8266 esp-12. It has lots of ram:

                  Sketch uses 235,469 bytes (22%) of program storage space. Maximum is 1,044,464 bytes.
                  Global variables use 34,412 bytes (42%) of dynamic memory, leaving 47,508 bytes for local variables. Maximum is 81,920 bytes.
                  

                  I might use a separate node for the controller, communicating using the nrf.

                  TheoLT Offline
                  TheoLT Offline
                  TheoL
                  Contest Winner
                  wrote on last edited by TheoL
                  #8

                  @mfalkvidd lots of ram is what we like. In case you're interested. This is a good i2c slave http://jamesreubenknowles.com/arduino-i2c-1680 tutorial and this is a great explanation of the i2c protocol

                  https://www.youtube.com/watch?v=6IAkYpmA1DQ

                  1 Reply Last reply
                  1
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  11

                  Online

                  11.7k

                  Users

                  11.2k

                  Topics

                  113.1k

                  Posts


                  Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • MySensors
                  • OpenHardware.io
                  • Categories
                  • Recent
                  • Tags
                  • Popular