Computer architecture
RAM, flash and EEPROM
Also called: SRAM · flash memory · EEPROM · volatile · non-volatile
Definition
RAM is fast, volatile working memory that loses its contents without power; flash and EEPROM are non-volatile and keep data, but are slower to write and wear out after many write cycles.
Picture it
On a microcontroller the program lives in flash and variables live in RAM. Saving a setting means writing flash or EEPROM, which takes milliseconds and has a limited number of erase cycles, so never write it every loop.
The maths
lifetime ≈ endurance (cycles) / writes per unit time
| Quantity | Unit | Symbol |
|---|---|---|
| information | byte (8 bits) | B |
| time | second | s |
Worked example
An EEPROM cell is rated for 100000 write cycles. If firmware saves a value once per second to the same cell, how long until the rating is reached?
- 100000 s / 3600 = 27.8 hours
- A little over a day
AnswerAbout 27.8 hours: save only when the value changes.
✓ The number in this answer is recomputed from scratch by an automated test.
Common misconceptions
- Misconception: Flash is not just slow RAM: it must be erased in blocks before rewriting.
- Misconception: Global variables in firmware live in RAM, not flash, unless marked constant.