Logic and computer systems · GCSE · OCR J277 1.2.1, AQA 8525 3.4.5, Edexcel 1CP2 3.1.1 · about 15 min
RAM, ROM, cache and virtual memory.
[1 mark]What does volatile mean?
[1 mark]What is ROM used for?
[1 mark]What is virtual memory?
[1 mark]Why does a computer slow down when it uses virtual memory a lot?
[1 mark]Put these in order from fastest to slowest.
Number the lines 1 to 4 to put them in the right order.
RegistersCacheSecondary storageRAMRegisters Cache RAM Secondary storage
Faster memory is smaller and costs more per gigabyte.
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.
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.