element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Blank Arduino Sketch Uses 450 Bytes of Program Storage Space and has 9 Bytes of Global Variable?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 22 replies
  • Subscribers 396 subscribers
  • Views 3322 views
  • Users 0 members are here
  • program
  • storage
  • arduino
  • variables
Related

Blank Arduino Sketch Uses 450 Bytes of Program Storage Space and has 9 Bytes of Global Variable?

oogutierrez
oogutierrez over 10 years ago

Does anyone know why a blank Arduino Sketch Uses 450 Bytes of Program Storage Space and has 9 Bytes of Global Variable? Why?

How does this compare with other AVR compilers?

 

image

  • Sign in to reply
  • Cancel

Top Replies

  • fvan
    fvan over 10 years ago +2
    There seems to be a detailed explanation here: Analysis of an Empty Arduino Sketch Frederick
  • balearicdynamics
    balearicdynamics over 10 years ago in reply to oogutierrez +2
    If you use the AVR Studio (I am using version 6) you see that the setup() and loop() functions can be defined to obtain the behaviour of the sketch IDE. Just the fact that you declare these functions mean…
  • mcb1
    mcb1 over 10 years ago in reply to clem57 +1
    Just to add. While the code shows nothing, there are various libraries and other settings that get compiled and sent to the board. Often its not the size of the sketch, but the libraries that take up most…
  • fvan
    fvan over 10 years ago

    There seems to be a detailed explanation here: Analysis of an Empty Arduino Sketch

     

    Frederick

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • oogutierrez
    oogutierrez over 10 years ago in reply to fvan

    thanks for the link. do you know if using other AVR compilers will use the about the same amount of space?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • clem57
    clem57 over 10 years ago in reply to oogutierrez

    They do vary, but something in the order of 400-500 bytes would be expected. If the AVR has more interfaces/pins, this would have more initialization code to setup. Even X86 has code on the boot drive to find what to load or put a message saying boot sector missing!

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • mcb1
    mcb1 over 10 years ago in reply to clem57

    Just to add.

    While the code shows nothing, there are various libraries and other settings that get compiled and sent to the board.

     

    Often its not the size of the sketch, but the libraries that take up most of the memory.

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • oogutierrez
    oogutierrez over 10 years ago in reply to mcb1

    I tried to compile again with only 1 variable of uint8_type and was expecting that the 9 bytes global variable from the blank sketch will become 10 bytes global variable but to my surprise it remained 9 bytes?

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • balearicdynamics
    balearicdynamics over 10 years ago in reply to oogutierrez

    The concept - valid on any other kind of environment too - is that the system when creates a blank stuff as in your case, it is NOT creating nothing, it is creating ONE THING: the blank stuff. So first of all you should see this apparently strange behaviour in the right perspective: the concept of "no program" should be represented just as any other program, and it occupy a space in the environment. Obviously minimal but it needs.

     

    The other aspect that is involved to this other "strange" behaviour, is related to the hardware and how the system represent data and bytes, instruction and so on. Bytes data architecture should follow internal hardware architecture so there is a standard bytes alignment, a minimal number of words occupied and so on. Then as your program grows a bit, if the aligned memory storage is sufficient it does not increase in size. This phenomenon is more explicitly visible as much you go near the machine language, as it occur in the case of microcontrollers programming.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • oogutierrez
    oogutierrez over 10 years ago in reply to oogutierrez

    If I assign a value to the _8bits varialble within the setup() subroutine, the bytes increases to the number of bytes of your variable.

    This time it increased to 10 bytes from 9 bytes because _8bits is a uint8_t which is 1 byte.

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • oogutierrez
    oogutierrez over 10 years ago in reply to oogutierrez

    what about a for loop that does nothing? well, it does not add to the program storage space nor to the global variable memory usage.

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • clem57
    clem57 over 10 years ago

    Compilers are smarter than us. If you allocate memory with no value, it is set aside and that is all. When you set a value, then a value is et in global to remember ot. No surprise to me, but I work with these for over 40 years. The loop may be optimized out of existence. I have seen this too. The behaviour is predictable IF you know how they generate code.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • oogutierrez
    oogutierrez over 10 years ago in reply to clem57

    thank you Clem, but thiss brings me back to pondering why a blank Arduino sketch would have the 9 bytes global variables when we have not used any yet.

    what are those 9 bytes for variables for?

    i wish we can compare it with other compilers or AVR IDE.

     

    i believe in other AVR IDEs it goes something like this

     

    int main(){

     

    /*main is like the setup section of arduino*/

     

    /**this is the loop section**/

    while(1)

    {

         //codes for the loop section here

    }

    /**end of loop section**/

     

     

    }

     

    if we compile this will we get similar byte usage with the Arduino.

    I am trying to understand one of the pros and cons of a given IDE.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube