Interactive Course

Computer Memory

How memory actually works, layer by layer.

Back

Overview

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

26

Concepts and exercises

175+

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.

      1
    2. Binary, Decimal, and Hexadecimal

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

      2
    3. Linear Memory Model

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

      3
    4. Memory Layout

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

      4
  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.

      5
    2. Memory Segments

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

      6
    3. The Code and Static Segments

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

      7
    4. The Stack Segment

      The stack allows multiple functions to work together.

      8
    5. The Heap Segment

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

      9
  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?

      10
    2. Virtual and Physical Memory

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

      11
    3. Memory Pages

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

      12
    4. MMU and the OS

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

      13
  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.

      14
    2. Memory Mapping

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

      15
    3. Demand Load

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

      16
    4. Page Sharing and Copy-on-Write

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

      17
  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.

      18
    2. Relocation

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

      19
    3. Position Independent Code

      An advanced technique can avoid the need for relocations.

      20
    4. Procedure Linkage Table

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

      21
  6. 6

    Caching

    A fundamental technique to improve performance.

    1. Caching Overview

      Caching is a fundamental technique for speeding up computer systems.

      22
    2. Details of Caching

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

      23
    3. Practical Uses of Caching

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

      24
    4. DRAM, SRAM, and CPU Caches

      Caching always needs to consider tradeoffs between cost and performance.

      25
    5. Computer Memory Architecture

      All modern processors use a similar pattern of caches.

      26