Interactive Course

Computer Memory

How memory actually works, layer by layer.



How is the memory managed in the running program? How does the OS manage it when multiple programs are running? What are the memory related features that the CPU provides?

This course will guide you through understanding memory management, layer by layer, so that you can answer the questions above and write efficient programs.

Topics covered

  • Compilation
  • Computer Memory Hierarchy
  • Copy-on-write
  • Hardware Caching
  • Least Recently Used Algorithm
  • Linking
  • Memory Mapping
  • Memory Segments
  • Position Independent Code
  • Time-aware Least Recently Used Algorithm
  • Virtual Memory

Interactive quizzes


Concepts and exercises


Course map

Prerequisites and Next Steps

  1. 1

    Introduction to Memory

    What memory is, and how to represent it.

    1. Retrieving Data from a Computer

      Computers work by storing data both quickly and slowly, both persistently and temporarily.

    2. Binary, Decimal, and Hexadecimal

      These three numeric bases from discrete math are key for understanding how computers really work.

    3. Linear Memory Model

      Discover how every computer program really sees the computer's memory when you get under the hood.

    4. Memory Layout

      The linear memory model allows large pieces of data to be stored in byte-sized fragments.

  2. 2

    Memory of Programs

    Segments of memory.

    1. Compiling Source Files to Executables

      The programs you run are made up of bytes in memory, just like everything else.

    2. Memory Segments

      A running program uses four different parts of the computer's memory four different purposes.

    3. The Code and Static Segments

      Some parts of memory are hold information that the program shouldn't be allowed to change.

    4. The Stack Segment

      The stack allows multiple functions to work together.

    5. The Heap Segment

      The heap is where memory for data structures can be easily allocated and freely shared.

  3. 3

    Virtual Memory

    How the OS manages memory.

    1. Processes

      A computer can hold many programs, each of which think they're using the same memory. How can this be?

    2. Virtual and Physical Memory

      Memory, as seen by every running computer program on your computer, is an elaborate virtual reality.

    3. Memory Pages

      The computer's actual memory is managed in large chunks, called "pages."

    4. MMU and the OS

      Your computer's processor and operating system work together to give each programs its own memory.

  4. 4

    Techniques for Performance

    OS features for efficient memory management.

    1. Page Cache

      The page cache keeps information from the hard drive in RAM for faster access.

    2. Memory Mapping

      A technique that helps the operating system access only small parts of big files.

    3. Demand Load

      Even after you think you've opened a file, the operating system may be lying to you.

    4. Page Sharing and Copy-on-Write

      Change is hard, and operating systems speed your computer up by assuming you'll avoid changes.

  5. 5

    Shared Libraries

    Linking and loading shared libraries to effectively reuse code.

    1. Libraries

      Programs do not exist in isolation. When they run, they need to be connected to libraries.

    2. Relocation

      After the compiler is done with your program, there is still missing information.

    3. Position Independent Code

      An advanced technique can avoid the need for relocations.

    4. Procedure Linkage Table

      See how the linkage information can be stored indirectly, without slowing programs down.

  6. 6


    A fundamental technique to improve performance.

    1. Caching Overview

      Caching is a fundamental technique for speeding up computer systems.

    2. Details of Caching

      Computer processors use a few different techniques for deciding what to cache.

    3. Practical Uses of Caching

      The same caching techniques apply to your computer and to the global internet.

    4. DRAM, SRAM, and CPU Caches

      Caching always needs to consider tradeoffs between cost and performance.

    5. Computer Memory Architecture

      All modern processors use a similar pattern of caches.