2079 1

CSC114 ยท 2079 ยท 10 marks

What is computer memory? Describe memory hierarchy with suitable example.

What is computer memory? Describe memory hierarchy with suitable example.[10]

Introduction to Information TechnologyChapter 3: Computer MemoryMemory Hierarchy

Quick answer

Computer memory is a device or component in a computer system that is used to store data, instructions, and intermediate results for processing. Memory allows the CPU to access and retrieve information quickly during the execution of programs.

Computer Memory and Memory Hierarchy

What is Computer Memory?

Memory can be broadly classified into:

  • Primary Memory (Main Memory): Directly accessible by the CPU (e.g., RAM, ROM, Cache)
  • Secondary Memory (Auxiliary Storage): Used for permanent storage (e.g., Hard Disk, SSD, Optical Disk)

The CPU uses registers to store data and instructions during processing, and data must be brought into the CPU's registers before it can be processed. This shows that memory plays a central role in every operation a computer performs.


Memory Hierarchy

The memory hierarchy is an arrangement of different types of memory in a computer system, organized from fastest and most expensive (smallest capacity) at the top to slowest and least expensive (largest capacity) at the bottom.

The key idea behind memory hierarchy is to balance speed, cost, and capacity so that the CPU can access data as quickly as possible while keeping the overall cost of the system reasonable.


Diagram of Memory Hierarchy

        ___________
       |  Registers |   <-- Fastest, Smallest, Most Expensive
       |___________|
      |    Cache    |
      |_____________|
     |  Main Memory  |
     |    (RAM/ROM)  |
     |_______________|
    |  Secondary Memory |
    |  (Hard Disk, SSD) |
    |___________________|
   |   Tertiary Memory   |
   | (Optical Disk, Tape)|
   |_____________________|
                            <-- Slowest, Largest, Least Expensive

Levels of Memory Hierarchy (Explained)


1. Registers (Level 1 - Top)

  • Registers are high-speed storage areas within the CPU itself.
  • They have the least storage capacity but are the fastest memory in the hierarchy.
  • They store data, instructions, and intermediate results of processing.
  • Registers are often referred to as the CPU's working memory.
  • Examples:
    • Accumulator (ACC): Stores the result of arithmetic and logic operations.
    • Instruction Register (IR): Contains the current instruction most recently fetched.
  • Capacity: A few bytes to a few hundred bytes
  • Speed: Extremely fast (nanoseconds or less)

2. Cache Memory (Level 2)

  • Cache memory is a small, high-speed memory located between the CPU and main memory.
  • It stores frequently used data and instructions so the CPU does not have to repeatedly access the slower main memory.
  • Cache is divided into levels: L1 Cache (inside CPU, fastest), L2 Cache, and L3 Cache (shared among cores).
  • Example: When a program runs a loop repeatedly, the loop instructions are stored in cache so the CPU can access them instantly.
  • Capacity: A few KB to a few MB
  • Speed: Very fast

3. Main Memory / Primary Memory (Level 3)

  • Main memory is the primary working memory of the computer, directly accessible by the CPU.
  • It includes:
    • RAM (Random Access Memory): Volatile memory that stores currently running programs and data. Data is lost when power is turned off.
    • ROM (Read Only Memory): Non-volatile memory that stores permanent instructions like the BIOS.
  • Main memory (RAM) is one of the key hardware components of a computer system.
  • Example: When you open a web browser, it is loaded from the hard disk into RAM so the CPU can access it quickly.
  • Capacity: A few GB (e.g., 4 GB, 8 GB, 16 GB)
  • Speed: Fast, but slower than cache

4. Secondary Memory (Level 4)

  • Secondary memory provides permanent (non-volatile) storage for data and programs.
  • It is much larger in capacity than primary memory but much slower to access.
  • The CPU cannot directly access secondary memory; data must first be transferred to main memory.
  • Examples: Hard Disk Drive (HDD), Solid State Drive (SSD), USB Flash Drive
  • The hard disk is a block device that transfers data as blocks.
  • Capacity: Hundreds of GB to several TB
  • Speed: Slower than RAM

5. Tertiary / Offline Memory (Level 5 - Bottom)

  • This is the lowest level of the memory hierarchy, used for backup and archival purposes.
  • It is the cheapest and largest in capacity but the slowest to access.
  • Examples: Optical Disks (CD, DVD, Blu-ray), Magnetic Tapes
  • Capacity: Can range from GB to PB (in tape libraries)
  • Speed: Very slow

Summary Table

Memory LevelExampleSpeedCapacityCost
RegistersACC, IRFastestBytesHighest
CacheL1, L2, L3 CacheVery FastKB - MBVery High
Main MemoryRAM, ROMFastGBModerate
Secondary MemoryHDD, SSDSlowGB - TBLow
Tertiary MemoryCD, TapeSlowestTB - PBLowest

Why is Memory Hierarchy Important?

  1. Speed: The CPU can access data from registers and cache almost instantly, reducing waiting time.
  2. Cost Efficiency: Expensive fast memory (registers, cache) is used in small amounts; cheap slow memory (hard disk) is used in large amounts.
  3. Performance: Frequently used data is kept in higher levels (cache/registers), improving overall system performance.
  4. Example: When you run a calculation, the numbers are loaded from the hard disk into RAM, then into cache, and finally into the CPU registers where the actual addition or subtraction takes place. The result is stored back in the accumulator register.

Conclusion

The memory hierarchy is a fundamental concept in computer architecture that balances the competing demands of speed, cost, and capacity. By organizing storage into registers, cache, main memory, secondary memory, and tertiary memory, a computer system can give the CPU the illusion of large, fast, and inexpensive memory all at once, which is essential for efficient program execution.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.