Search topics...
C / C++ ConceptsMemory Layoutfoundational

What is the difference between .data and .bss, and why does it matter?

0 upvotes
Practice with AISoon

.data holds globals/statics initialized to nonzero values — their initial values must be stored in flash and copied to RAM at boot. .bss holds globals/statics that are zero-initialized — only the section size is stored, and the startup code memsets it to zero.

The practical implication: a large array like uint8_t buf[4096] = {0}; goes in .bss and costs 4 KB of RAM but zero flash. The same array initialized to {1, 2, 3, ...} goes in .data and costs 4 KB of RAM plus 4 KB of flash for the initializers, plus boot time to copy it. On flash-constrained MCUs, this distinction matters significantly.

Source: C / C++ Concepts Q&A