All subjects · Computer Science · WCP01 Principles of Computer Science

Memory management: paging, segmentation, virtual memory and the call stack

Edexcel IAL Computer Science · WCP01 Principles of Computer Science

The OS must track which memory is free, decide how much each process needs and stop processes interfering. Spec point 1.2.4 covers how it allocates memory and how a call stack stores stack frames.

Practise this in the app: instant marking and a fix for every mistake. Free, no email needed to start.

Practise this lesson

What memory management does

Paging and segmentation

Virtual memory

Virtual memory uses part of secondary storage as if it were extra RAM. When RAM is full, pages not currently needed are swapped out to disk; when they are needed again, they are swapped back in.

The call stack and stack frames

When a subroutine (function) is called, a stack frame is pushed onto the call stack. It holds:

The stack pointer holds the address of the top of the stack. When the subroutine returns, its frame is popped and execution continues at the return address. Nested or recursive calls add a frame each time; too many causes a stack overflow.

Worked example

main() calls area(4, 5), and area calls square(4). Show the call stack while square is running.

  1. Bottom: frame for main.
  2. Next: frame for area, holding the return address in main, parameters 4 and 5, and its local variables.
  3. Top: frame for square, holding the return address in area, parameter 4 and its local variables.
  4. The stack pointer points to the square frame.

Answer: Top to bottom: square, area, main. Frames are popped in reverse order as each function returns.

Key idea: Memory manager tracks, sizes and controls allocation. Paging: fixed-size pages and frames, internal fragmentation. Segmentation: variable logical segments, external fragmentation. Virtual memory: disk as RAM, thrashing. Stack frame: return address, parameters, local variables.

Check yourself

  1. A process of 13 KiB is loaded into a system that uses 4 KiB pages. How many pages are needed?
    Show answer

    4. 13 / 4 = 3.25, so 4 pages (pages cannot be split).

  2. In the same system (4 KiB pages, 13 KiB process), how many KiB of the last page are unused?
    Show answer

    3 KiB. 4 pages = 16 KiB; 16 - 13 = 3 KiB of internal fragmentation.

  3. Which statement describes segmentation?
    • Memory is divided into equal-sized frames
    • Secondary storage is used as extra RAM
    • The CPU checks for interrupts after every instruction
    • A process is divided into variable-sized blocks that match its logical parts
    Show answer

    A process is divided into variable-sized blocks that match its logical parts. Segments are logical units such as code, data and stack.

  4. What is disk thrashing?
    • Spending more time swapping pages between RAM and disk than executing processes
    • A hard disk spinning too fast
    • Deleting files to free up space
    • Pages being stored in cache
    Show answer

    Spending more time swapping pages between RAM and disk than executing processes. Too little RAM for the active pages leads to constant swapping.

  5. Which item is not stored in a stack frame?
    • The return address
    • The parameters passed to the subroutine
    • The page table for the whole system
    • Local variables of the subroutine
    Show answer

    The page table for the whole system. The page table belongs to the memory manager, not to a function call.

  6. Explain one benefit and one drawback of virtual memory.
    Show answer

    Benefit: more programs, or larger programs, can run than the physical RAM allows. Drawback: secondary storage is much slower than RAM, so swapping slows the computer and can lead to thrashing.. One benefit (capacity) and one drawback (speed, thrashing).

  7. When a function returns, what happens to its stack frame?
    • It stays on the stack until the program ends
    • It is copied to secondary storage
    • It is popped and execution continues at the return address
    • It is moved to the bottom of the stack
    Show answer

    It is popped and execution continues at the return address. The stack is last in, first out; the finished function's frame is removed.

  8. Which type of fragmentation is associated with paging?
    • External fragmentation
    • Data fragmentation on a network
    • Packet fragmentation
    • Internal fragmentation
    Show answer

    Internal fragmentation. Fixed-size pages leave unused space inside the last page.

Practise with instant feedback

Sources

Last updated 8 November 2026. Spotted a mistake? Tell us.