Is there an overhead in flash memory usage?

Beginner's question:
When programming a microcontroller with limited flash memory with the Arduino IDE but without burning Arduino bootloader, is there a storage overhead besides the size of the sketch itself?

For example, let's say I have a non-demanding task that works with an Arduino and I want to run it with an ATtiny13A. The code has about 1000 characters including spaces and paras. Will this fit in the ATtiny's 1024 byte flash memory?

That does not mean much.

Install a board package that supports the ATtiny13A and compile the sketch for that processor/board. The IDE will (should) tell you the memory usage.

Your code doesn't upload to board as is, it must be compiled first. The length of the C source code has nothing to do with size of binary firmware

@Pimpom "Nothing" is a bit misleading. In general, a larger source code file will result in a larger binary file and a smaller source code file will result in a shorter binary file. The point is that the size of the binary file can vary considerably depending on exactly what the source code file contains. Two source files of roughly the same size could have very different binary file sizes.

This is, among other factors, because of library files. The libraries your code explicitly includes are only part of the picture. Many more libraries are included implicitly by the Arduino core for the board you are using. If you add the length of your code to the length of all those libraries, it is a wonder that any code will fit into the Arduino!

Fortunately, the C compiler and linker are pretty clever, and will remove all of the code in those library files that is not actually needed, based on the code in your source file. This brings the total binary file size down dramatically.

Thanks for the replies. I think I understand the points raised. I have a good background with analog and fixed logic circuits but am still in kindergarten as far as MCUs, uPs and any programmable devices are concerned.

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