Data Representation and Binary
Main memory is fast and nearly as quick as the CPU, but it is volatile and loses all data when power is cut off.
Two Jobs of Computer Memory
When a program is running, a computer needs two apparently conflicting abilities. It must access active instructions and data quickly, and it must preserve programs and files when the power is turned off. A single memory system cannot provide both the speed needed for active processing and the persistence needed for long-term storage. Computers therefore use multiple memory systems, each optimized for a different role.
Main memory is optimized for fast active work. Secondary memory is optimized for retaining data without power.
A Program's Route Through Main Memory
The CPU does not work directly with files stored on a hard drive. When you start a program, the operating system copies that program from secondary memory into main memory. The CPU then executes the program from main memory, where the information is available almost instantly compared with secondary memory. Data that the program needs to process is also placed in main memory.
The Speed-Persistence Trade-off
Main memory is fast and nearly as quick as the CPU, but it is volatile. Volatile memory requires constant power to retain its data. When power is cut off, the data in main memory is lost. Secondary memory is much slower, but it is non-volatile: it retains data without power. This makes secondary memory suitable for storing programs and files over the long term.
| Memory type | Speed role | Power requirement | Typical purpose |
|---|---|---|---|
| Main memory | Fast and nearly as quick as the CPU | Requires constant power | Active program instructions and data |
| Secondary memory | Much slower than main memory | Retains data without power | Long-term storage of programs and files |
The central trade-off between active processing and persistent storage
Saving and Loading a Web Browser
From stored program to active webpage
Trace what happens when a user opens a web browser, loads a webpage, and then closes the browser without saving the page.
Load the browser: The browser application is stored on secondary memory, such as a hard drive. When the user clicks the browser icon, the operating system copies the program into main memory.
Execute the program: The CPU executes the browser code from main memory rather than working directly with the hard-drive file.
Request the webpage: After the user enters a web address, the browser sends a request over the network.
Receive and process data: The web server sends webpage data back over the network. The data arrives in main memory, where the CPU processes it and the computer displays it.
Close without saving: If the page data has not been saved to secondary memory, closing the browser causes that data to be lost from main memory. The browser application remains on the hard drive.
The browser must be loaded into main memory for the CPU to run it, while the stored browser application remains available on secondary memory for future use.
Choosing Secondary Memory
Secondary memory includes disk drives, such as hard disk drives and solid-state drives, and flash memory, such as the memory found in USB sticks and portable music players. These technologies retain data without power, so they are appropriate for long-term storage. The source distinguishes them as examples of secondary memory rather than assigning each one a separate performance rule.
| Type | Example | Appropriate role |
|---|---|---|
| Disk drive | Hard disk drive | Long-term storage of programs and files |
| Disk drive | Solid-state drive | Long-term storage of programs and files |
| Flash memory | USB stick | Portable long-term storage |
| Flash memory | Portable music player | Retaining stored data without power |
When a program's result must survive the end of the program or a shutdown, explicitly write that result to secondary memory. Keeping the result only in main memory does not make it persistent.
Network Storage and Its Limits
A network connection can act as a slow and unreliable form of secondary memory because it provides access to data stored remotely. Instead of reading data from local secondary memory, a computer sends a request over the network and receives data from a remote server. This is useful for remote access, but the data cannot be reached as directly or reliably as data already available locally. Network connections are therefore unsuitable for critical, time-sensitive operations.
Mistakes About Memory and Saving
Assuming the CPU runs a program directly from a hard drive
The CPU works with data in main memory. The operating system first copies the program from secondary memory into main memory.
Fix:
Think of the hard drive as persistent storage and main memory as the place where active execution occurs.Treating main memory as permanent storage
Main memory is volatile and loses its data when power is cut off.
Fix:
Save the document to secondary memory when it must remain available.Assuming a network connection is as dependable as local storage
Network connections are described as slow and unreliable forms of secondary memory.
Fix:
Account for remote-access limitations and avoid relying on network access for critical, time-sensitive operations.
Check the Data Path
A program reads a file, changes its contents, and then finishes. Identify where the program must obtain the file before the CPU can process it, and identify what must happen if the changed contents need to remain after the program finishes.
Hints
- The CPU works with data in main memory.
- A result that must survive shutdown must be written to secondary memory.
What do you think happens?
A user opens a browser, receives webpage data, and closes the browser without saving the page. Which information can be lost from main memory, and which program remains available?
Reveal answer
Answer: The webpage data can be lost; the browser application remains on secondary memory.
The webpage data was active in main memory and was not saved. The browser application was already stored on the hard drive, so it remains available for loading again.
Memory Roles at a Glance
- Main memory is fast and provides the CPU with the instructions and data needed for active processing.
- Main memory is volatile, so its contents disappear when power is cut off.
- Secondary memory is slower but non-volatile, making it suitable for long-term storage of programs and files.
- Disk drives and flash memory are examples of secondary memory that retain data without power.
- Network connections provide remote access to data but are slow and unreliable, so they are unsuitable for critical, time-sensitive operations.
Key Takeaways
- The CPU works with program instructions and data in main memory rather than directly with files on a hard drive.
- Main memory favors speed but is volatile; secondary memory favors persistence but is much slower.
- Saving explicitly copies data from main memory to secondary memory so it can survive shutdown.
- Disk drives and flash memory provide examples of non-volatile secondary memory.
- Network connections can provide remote data access, but their slowness and unreliability limit their use for time-sensitive work.