Secondary storage
Magnetic, optical, solid state and cloud storage, and choosing between them.
Do this lesson in the simulatorRAM forgets everything when the power goes off, so a computer also needs secondary storage: non-volatile storage that keeps programs and files until they are deleted. Your saved lesson work, the photos on a phone, and the program saved on BugBot all live in secondary storage. There are three technologies, and choosing between them is a favourite exam question.
Why secondary storage?
- It is non-volatile: files stay when the power is off.
- It holds far more than RAM, for far less money per gigabyte.
- It is slower than RAM, so programs are copied from storage into RAM to run.
Three technologies
Magnetic: a hard disk drive (HDD) stores bits as tiny magnetised areas on spinning metal platters, read by a head on a moving arm. Magnetic tape is used for very large backups.
Optical: CDs, DVDs and Blu-ray discs store bits as pits and flat areas, read by a laser.
Solid state: SSDs, USB memory sticks and SD cards store bits as electrical charges in flash memory chips. There are no moving parts. The program you upload to BugBot is saved in flash memory on its main board.
Choosing storage
Every choice is a trade-off between these characteristics:
| Characteristic | Magnetic (HDD) | Optical | Solid state (SSD, SD card) |
|---|---|---|---|
| Capacity | very high | low | high |
| Speed | medium | slow | very fast |
| Portability | heavy, for a disk | light discs | small and light |
| Durability | moving parts; can be damaged if dropped | scratches easily | no moving parts; survives knocks |
| Reliability | good, but parts wear out | discs degrade over years | good, but each cell has limited writes |
| Cost per GB | very low | low | higher |
A robot that shakes itself across a mat, like BugBot, must use solid state: a spinning disk would not survive the vibration. A school keeping years of backups wants the lowest cost per gigabyte: a hard disk or tape.
Cloud storage
Cloud storage keeps your files on someone else's servers, reached over the internet. The servers themselves use magnetic and solid state drives.
- It can be reached from any device with an internet connection, and is easy to share.
- The provider handles backups, and storage can be added as needed.
- It needs an internet connection, may cost a subscription, and your data is held by another company.
Speed matters too
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
file_mb = 4000 # a 4 GB video
speeds = {"Blu-ray": 20, "hard disk": 150, "SD card": 90, "SSD": 3000} # MB per second, roughly
for device, mb_per_s in speeds.items():
print(f"{device}: {file_mb / mb_per_s:.1f} seconds to read the video")
Task: the storage chooser
Write choose(needed_gb, no_moving_parts). It returns the name of the cheapest device in devices whose capacity is at least needed_gb, and which has no moving parts if no_moving_parts is True. A device's price in pence is its capacity times its pence per GB. Print one line for each job in jobs, in the form robot logs: SD card.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# name, capacity in GB, pence per GB, has moving parts
devices = [
("hard disk", 2000, 2, True),
("SSD", 1000, 6, False),
("SD card", 256, 10, False),
("Blu-ray", 50, 4, False),
]
# job, GB needed, needs no moving parts
jobs = [("robot logs", 64, True), ("school backups", 1500, False), ("video editing", 500, True), ("film archive", 40, False)]
Challenges
- Add a reading speed to each device, and let
chooserequire a minimum speed. - Add magnetic tape: 12000 GB at 0.5 pence per GB. Which jobs change?
- Write three sentences recommending storage for a school trip camera, using three different characteristics.