How Memory Works

What is Memory?

The fundamental purpose of memory, whether human or machine, is to store information over time. A striking aspect of human memory is its remarkable ability to forget. While this may initially seem like a flaw, it serves as an advantageous strategy for focusing on what truly matters amidst the constant influx of stimuli in our lives. Forgetting acts as a means of prioritizing important information and discarding irrelevant details, akin to clearing out old items from a closet to make space for new ones.
Unlike human memory, computers do not operate in the same manner of remembering and forgetting. Instead, they function in binary—either knowing something or not. Once computers acquire knowledge, they typically retain it indefinitely, barring any catastrophic failures. Humans, on the other hand, possess the ability to recognize familiar things or recall learned information without necessarily being able to retrieve them at will. This cyclical process of forgetting and remembering gives human memory a nuanced and almost magical quality, distinct from the more deterministic nature of computer memory.
While celebrated individuals may master techniques enabling them to memorize vast amounts of information, their feats are often likened to acts of magic or artistry. Yet, in comparison to the straightforward storage capabilities of a modest USB flash drive, the achievements of these individuals pale in comparison—underscoring the contrast between human memory's complexity and the straightforward functionality of computer memory.

The two types of memory

Human brains and computers share the characteristic of having different types of memory. Human memory is divided into short-term "working" memory, which holds recently processed information, and long-term memory, which stores facts, experiences, and learned skills for extended periods. Similarly, computers typically feature two distinct kinds of memory.
Firstly, there's the built-in main memory, also known as internal memory, comprised of silicon chips or integrated circuits. This memory facilitates rapid data storage and retrieval, assisting the computer in processing tasks at hand. Main memory is volatile, meaning it loses its contents when the power is turned off. To address this limitation, computers are equipped with auxiliary memory or storage, which retains information even when power is disconnected. In desktops or laptops, auxiliary memory is commonly provided by hard drives or flash memory. It's also referred to as external memory, harking back to older, larger computers where it resided in a separate machine linked to the main computer box via a cable. In modern PCs, auxiliary storage can take various forms such as USB flash drives, SD memory cards (used in devices like digital cameras), plug-in hard drives, CD/DVD ROMs, and rewriters.

In practical terms, the distinction between main memory and auxiliary memory can become somewhat blurred. Computers typically have a limited amount of main memory, ranging from around 512MB to 4GB in modern systems. The more main memory a computer has, the faster it can process information and complete tasks. However, if a computer needs to store more data than its main memory can accommodate, it employs a technique called virtual memory.
Virtual memory allows the computer to temporarily transfer less critical data from main memory to its hard drive, freeing up space in main memory. This process enables the computer to continue functioning when it exceeds its physical memory limits. However, accessing data from a hard drive is significantly slower than from main memory due to mechanical limitations, leading to decreased performance. When virtual memory is activated, you may hear the hard drive operating rapidly as it reads and writes data between virtual and physical memory.
Ultimately, computers with more main memory operate more efficiently because they can handle larger amounts of data without relying heavily on slower virtual memory operations. Increasing main memory reduces the frequency of virtual memory usage, resulting in improved system performance.

  1. Internal Memory:
    1. Internal memory refers to all types of memory directly accessible by the CPU within the computer system.
    2. It includes both volatile and non-volatile memory memory components.
    3. Examples of it include RAM (Random Access Memory), ROM (Read-Only Memory), cache memory, and registers.
  2. Main Memory (Primary Memory):
    1. It is subset of internal memory that serves as the main storage location for data and instructions that the CPU actively uses.
    2. It includes volatile memory components such as RAM, which are directly accessible by the CPU and used for temporary storage of data during program execution.
    3. It is typically faster and more expensive than secondary memory but has limited storage capacity.
  3. Secondary Memory (Auxiliary Memory):
    1. It refers to storage devices that are external to the CPU and main memory, used for long-term storage of data and programs.
    2. It includes non-volatile memory components such as hard disk drives (HDDs), solid-state drives (SSDs), optical drives (CD-ROMs, DVD-ROMs), and magnetic tapes.
    3. Secondary memory provides larger storage capacity compared to main memory but has slower access times.

Internal Memory types

The internal memory of a computer is commonly categorized into two main types: Random Access Memory (RAM) and Read-Only Memory (ROM).

  1. Random Access Memory (RAM):
    1. RAM is a type of memory that allows data to be read or written to any order, enabling quick access to stored information.
    2. It serves as temporary storage for data and instructions that the CPU actively uses during program execution.
    3. RAM is volatile, meaning its content are lost when the computer is powered off. This characteristic makes it ideal for storing data that needs to be accessed quickly but doesn't need to be retained permanently.
    4. RAM is further subdivided into different types such as Dynamic RAM (DRAM) and Static RAM (SRAM), each with its own characteristics regarding speed, power consumption, and cost.
  2. Read-Only Memory (ROM):
    1. ROM is a type of memory that contains pre-programmed data or instructions that cannot be easily modified or overwritten.
    2. It is used to store firmware and essential system software that the computer needs to boot up and perform basic functions before loading the operating system.
    3. ROM is non-volatile, meaning its contents are retained even when the computer is powered off. This makes it suitable for storing critical system-level data that should not be altered.
    4. There are different types of ROM, including Mask ROM (factory-programmed), Programmable ROM (PROM), Erasable Programmable ROM (EPROM), and Electrically Erasable Programmable ROM (EEPROM), each with varying levels of flexibility and reprogrammability.

DRAM and SRAM

RAM comes in two main varieties called DRAM (Dynamic RAM) and SRAM (Static RAM).

  1. Dynamic Random Access Memory (DRAM):
    1. DRAM is a type of volatile memory that stores each bit of data as an electric charge in a capacitor within an integrated circuit.
    2. It requires constant refreshing of its memory cells to maintain the stored data, as the electric charge stored in capacitors tends to leak over time.
    3. DRAM is typically used for main memory in computers due to its high storage density and lower cost compared to SRAM.
    4. It offers slower access times compared to SRAM due to the need for periodic refresh cycles.
    5. DRAM modules are commonly used in systems as DIMMs (Dual Inline Memory Modules) or SO-DIMMs (Small Outline DIMMs).
  2. Static Random Access Memory (SRAM):
    1. SRAM is a type of volatile memory that stores data using flip-flop circuits, which retain their state as long as power is supplied to the circuit.
    2. Unlike DRAM, SRAM does not require periodic refreshing of its memory cells, making it faster and more power-efficient.
    3. SRAM offers faster access times compared to DRAM, making it suitable for use in cache memory and other applications where high-speed access is crucial.
    4. However, SRAM is more expensive and has lower storage density compared to DRAM.
    5. SRAM is commonly used in cache memory, register files, and other applications where high-speed access is critical.

Differences between different types of memory

Memory TypeVolatilityAccessibilitySpeedPersistenceCapacityExamples
RAM (Random Access Memory)VolatileDirectly accessible by CPUFastData is lost when powered offLimited by hardware constraintsDDR4, DDR3, SRAM, DRAM
ROM (Read-Only Memory)Non-volatileDirectly accessible by CPUFastData is permanentFixed (depends on ROM size)BIOS ROM, Firmware ROM, Mask ROM
Cache MemoryVolatileDirectly accessible by CPUVery FastData is temporaryLimited (smaller than RAM)L1 Cache, L2 Cache, L3 Cache
RegistersVolatileDirectly accessible by CPUUltra FastData is temporaryExtremely limited (few KBs)General Purpose Registers, Instruction Registers, etc.
Virtual MemoryBoth volatile & non-volatileIndirectly accessible by CPU (managed by OS)Slower than RAMData may be swapped to diskVirtually unlimitedPaging file (swap), Page tables, Virtual memory mappings
Hard Disk Drive (HDD)Non-volatileIndirectly accessible by CPUSlow (compared to RAM)Data is permanentLarge (typically several TBs)Traditional mechanical hard drives
Solid State Drive (SSD)Non-volatileIndirectly accessible by CPUFaster than HDDData is permanentLarge (typically several TBs)Flash-based storage devices
Optical Discs (CD-ROM, DVD-ROM, etc.)Non-volatileIndirectly accessible by CPUSlower than HDDData is permanentLimited (depends on disc capacity)CD-ROMs, DVD-ROMs, Blu-ray Discs
Magnetic TapesNon-volatileIndirectly accessible by CPUSlowestData is permanentExtremely large (several PBs)Magnetic tape storage systems

                       +-----------------------------------+
                       |            Computer               |
                       +-----------------------------------+
                                /            |             \
                               /             |              \
                              /              |               \
                  +----------------+ +----------------+ +----------------+
                  | Internal       | | Main Memory    | | Secondary      |
                  | Memory         | | (Primary       | | Memory         |
                  |                | | Storage)       | |                |
                  +----------------+ +----------------+ +----------------+
                        /    \               |                 /   \
                       /      \              |                /     \
                      /        \             |               /       \
           +-------------+ +------------+ +------------+ +--------------+
           | Cache       | | Registers  | | RAM        | | Secondary    |
           | Memory      | |            | |            | | Memory       |
           | (High-speed)| | (Ultra-    | | (Volatile) | | Devices      |
           | Temp)       | | fast)      | |            | | (Non-        |
           +-------------+ +------------+ +------------+ | Volatile)    |
                                                         +--------------+

Hierarchy of Memory

        +--------------------------------------------------------+
        |                    Memory Hierarchy                     |
        +--------------------------------------------------------+
        |                    Internal Memory                      |
        | +----------------------------------------------------+  |
        | |                    Cache Memory                    |  |
        | |                 (L1, L2, L3 Cache)                 |  |
        | +----------------------------------------------------+  |
        | |                    Registers                       |  |
        | |               (Inside CPU Core)                    |  |
        | +----------------------------------------------------+  |
        |                                                         |
        |                    Main Memory (RAM)                    |
        | +----------------------------------------------------+  |
        | |                 Main System Memory                 |  |
        | |                 (Volatile, Fast)                   |  |
        | +----------------------------------------------------+  |
        |                                                         |
        |                    Secondary Memory                     |
        | +----------------------------------------------------+  |
        | |                    SSDs, HDDs,                     |  |
        | |                Optical Discs, Tapes                |  |
        | +----------------------------------------------------+  |
        |                                                         |
        +--------------------------------------------------------+

This Memory Hierarchy Design is divided into 2 types:

  • Primary or Internal Memory: It consists of CPU registers, Cache Memory, Main memory, and these are directly accessible by the processor.
  • Secondary or external Memory: It consists of a magnetic disk, optical disk, magnetic tape, which are accessible by processor via I/O module.