The worksheetDownload the PDF
Answers

F9.6 Memory

Logic and computer systems · GCSE · OCR J277 1.2.1, AQA 8525 3.4.5, Edexcel 1CP2 3.1.1 · about 15 min

BugBotLab

What this lesson is about

RAM, ROM, cache and virtual memory.

Questions 5 marks in all

  1. [1 mark]What does volatile mean?

    1. AThe contents are lost when the power is off
    2. BIt can only be read
    3. CIt is very fast
    4. DIt is stored on a disk
    Answer: A. RAM is volatile; ROM is not.
  2. [1 mark]What is ROM used for?

    1. AHolding the boot program that starts the computer
    2. BHolding the programs currently running
    3. CStoring a user's files
    4. DSpeeding up the CPU with copies of data
    Answer: A. The boot instructions must be there when the power comes on.
  3. [1 mark]What is virtual memory?

    1. APart of secondary storage used as extra RAM when RAM is full
    2. BMemory inside the CPU
    3. CRAM that keeps its contents without power
    4. DMemory on another computer
    Answer: A. The OS moves data not in use out to storage.
  4. [1 mark]Why does a computer slow down when it uses virtual memory a lot?

    1. ASecondary storage is much slower than RAM
    2. BVirtual memory uses more power
    3. CThe CPU stops while it is used
    4. DVirtual memory is smaller than RAM
    Answer: A. Moving data back and forth to storage takes time. More RAM is the fix.
  5. [1 mark]Put these in order from fastest to slowest.

    Number the lines 1 to 4 to put them in the right order.

    1. Registers
    2. Cache
    3. Secondary storage
    4. RAM
    Answer:
    Registers
    Cache
    RAM
    Secondary storage

    Faster memory is smaller and costs more per gigabyte.

The task: out of RAM

A computer has 4 GB of RAM, and the operating system always uses 1 GB. The apps in apps are opened in order. For each one, while it does not fit, move the app that has been in RAM longest to virtual memory and print moved <name> to virtual memory. Then load it and print <name> -> RAM. At the end, print RAM used: <n> GB and in virtual memory: <names>, the names joined with , .

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

ram_size = 4
os_size = 1
apps = [("browser", 1.5), ("game", 2.0), ("music", 0.5), ("editor", 1.0)]

The hint students can ask for: Keep a list of what is in RAM, oldest first, and a list of what has been moved out. Before loading an app, keep moving the oldest out while it still does not fit, remembering the operating system's share.

A solution

from bugbot import *
connect()
ram_size = 4
os_size = 1
apps = [("browser", 1.5), ("game", 2.0), ("music", 0.5), ("editor", 1.0)]
in_ram = []
virtual = []

def used():
    return os_size + sum(size for name, size in in_ram)

for name, size in apps:
    while used() + size > ram_size:
        old = in_ram.pop(0)
        virtual.append(old[0])
        print("moved", old[0], "to virtual memory")
    in_ram.append((name, size))
    print(name, "-> RAM")
print("RAM used:", used(), "GB")
print("in virtual memory:", ", ".join(virtual))

Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.