Types of Memory
Memory and storage can be classified into three groups: primary memory, cache and persistent storage.
Primary Memory: RAM and ROM
Understanding Primary Memory
Primary memory is the only storage directly accessible by the CPU. It holds data and instructions currently in use, stored
Primary memory
The only storage directly accessible by the CPU. It holds data and instructions currently in use, stored as binary machine code.
as binary machine code.
Primary memory has two components:
- Random Access Memory (RAM)
- RAM holds executing program instructions and any necessary data.
- Each piece of data is stored in a unique memory location with an address and content.
- Read-Only Memory (ROM)
- ROM holds instructions and data in unique memory locations, similar to RAM.
- These instructions are critical for booting and basic system operations.
Imagine working on a document. The unsaved changes reside in RAM. If the power goes out, those changes are lost.
ExampleThe BIOS (Basic Input/Output System) is stored in ROM. It initializes hardware components during startup.
NoteROM is often smaller than RAM but plays a crucial role in system stability by providing essential startup instructions.
| Feature | RAM | ROM |
|---|---|---|
| Volatility | Volatile (loses data when power is off) | Non-volatile (retains data without power) |
| Modifiability | Read and write (continuously updated with executing program instructions and data) | Read-only |
| Purpose | Stores executing programs and data | Stores permanent instructions (e.g., BIOS) |
| Size | Typically larger | Smaller |
| Upgradability | Usually upgradeable, can be increased | Usually part of motherboard, difficult to upgrade |
| Use Case | Running applications and temporary data storage | Booting and essential system operations |
Think of RAM as a workspace where you actively work on tasks, while ROM is a reference book with essential instructions that never change.
Common MistakeDon't confuse RAM and ROM. RAM is for temporary, volatile storage, while ROM is for permanent, non-volatile instructions.
Cache
Cache memory
Cache memory is a high-speed memory located close to the CPU, designed to store frequently accessed data and instructions.
Cache memory is typically made of Static RAM (SRAM), which is faster but more expensive than the Dynamic RAM (DRAM) used in main memory.
A cache memory significantly reduces the time it takes for the CPU to access data, as it is much faster than RAM.
Analogy- Think of cache memory as a personal assistant who keeps your most important documents on hand.
- Instead of searching through a filing cabinet (RAM) every time you need something, you can quickly access what you need from your assistant (cache).
Cache works in a few steps:
- Data Request: When the CPU needs data, it first checks the cache.
- Cache Hit: If the data is in the cache, it's retrieved quickly.
- Cache Miss: If the data is not in the cache, it's fetched from RAM and stored in the cache for future use.
Cache can have multiple levels:
- L1 Cache:
- Located on the CPU chip.
- Smallest and fastest.
- Divided into separate caches for instructions and data.
- L2 Cache:
- Larger than L1.
- May be on the CPU or a separate chip.
- L3 Cache:
- Shared among multiple CPU cores.
- Larger and slower than L1 and L2.
- Modern CPUs often have multiple cache levels to balance speed and cost.
- Each level is progressively larger and slower.
- Consider a video editing application.
- The CPU frequently accesses the same set of instructions and data (e.g., rendering algorithms, video frames).
- By storing these in the cache, the application runs more smoothly and efficiently.
In multicore systems, each core may have its own cache.
Cache coherency ensures that all caches have a consistent view of memory:
- Write-Through: Data is written to both the cache and main memory simultaneously.
- Write-Back: Data is written to the cache first and only updated in main memory when evicted from the cache.
Cache coherency protocols, such as MESI (Modified, Exclusive, Shared, Invalid), manage data consistency across multiple caches.
Using cache does not always mean good. Disadvantages include:
- Cost: Cache memory is expensive due to its high speed and complexity.
- Size: Limited size means only a small portion of data can be stored.
- Complexity: Managing cache coherency and eviction policies adds complexity to system design.
- Don't assume that increasing cache size will always improve performance.
- The benefits diminish if the cache becomes too large relative to the workload.
Persistent Storage
Persistent storage refers to non-volatile storage that retains data even when the power is turned off. This is in contrast to volatile memory like RAM, which loses all data when the system is powered down.
NotePersistent storage is often referred to as secondary storage or auxiliary storage.
Analogy- Think of persistent storage as a library.
- Books (data) are stored on shelves (storage devices) and can be accessed whenever needed, even if the library (computer) is closed (powered off).
We need persistent storage for:
- Data Retention
- Without persistent storage, all data would be lost when a computer is turned off.
- This would make it impossible to save files, applications, or system settings.
- Additionally, persistent storage enables the implementation of data encryption, ensuring data integrity and security.
- Program Execution:
- Applications are stored in persistent storage and loaded into RAM when needed.
- Without it, a computer would be unable to run software.
- Additionally, persistent storage is used to extend the capacity of RAM through techniques like virtual memory, allowing systems to run larger applications than would otherwise be possible.
- Data Backup:
- Persistent storage provides a reliable way to back up important data, protecting it from accidental loss or corruption.
- High Capacity:
- Persistent storage devices, such as hard drives and SSDs, offer much larger capacities than RAM, allowing for the storage of large files and databases that modern applications, such as databases and machine learning models, require.
When designing a system, always consider the balance between speed (RAM) and capacity (persistent storage) to ensure optimal performance.
Types of Persistent Storage
- Hard Disk Drives (HDDs):
- Use spinning disks coated with magnetic material to store data.
- They offer high capacity at a lower cost but are slower than SSDs.
- Solid State Drives (SSDs):
- Use flash memory to store data, providing faster read and write speeds than HDDs.
- They are more expensive but offer better performance and durability.
- Optical Discs:
- Such as CDs, DVDs, and Blu-rays, use laser technology to read and write data.
- They are often used for media distribution and backups.
- Flash Drives:
- Portable storage devices that use flash memory.
- They are convenient for transferring data between systems.
- Cloud Storage:
- Stores data on remote servers accessed via the internet.
- It offers scalability and accessibility from anywhere with an internet connection.
While cloud storage is convenient, it relies on internet connectivity and raises concerns about data privacy and security.
Self review- What happens to the data in RAM when the computer is turned off?
- Why is ROM considered non-volatile?
- How do RAM and ROM work together during the boot process?
- Why is persistent storage essential for modern computer systems?
- How does persistent storage differ from primary memory (RAM)?
- What are some common types of persistent storage devices, and what are their advantages and disadvantages?
- How does the design of primary memory reflect broader principles of efficiency and reliability in technology?
- How does the concept of cache memory reflect broader patterns of optimisation and efficiency in technology and other fields?
- How does the concept of persistent storage influence our understanding of memory and permanence in the digital age?