Menu

System Software

Memory Management and Multitasking

Contents

  1. Transfer of Programs and Data
  2. Memory Allocation and Protection
  3. Memory Management Compared with Other OS Functions

When a program is not being used, the program and its data are kept on secondary storage, such as a tablet's built-in storage or a USB stick. Secondary storage is non-volatile, so it keeps its contents when the power is off, and it has a large capacity, so it can hold many programs and files.

The CPU cannot run a program directly from secondary storage. It can only fetch instructions and data that are held in RAM (random access memory). That is why the operating system has to move programs and their data between secondary storage and RAM.

Opening a program

When you open a program, the operating system loads the program into RAM, together with any files it needs. For example, if you open a cooking app to view a recipe, the app's instructions and the recipe file are copied into RAM.

While the program is running, the CPU takes the instructions it needs, and the data they work on, from RAM, and anything it works out is kept there too. If you change the recipe's serving size, the new amounts are worked out and stored in RAM.

Saving and closing

When you save your work, the operating system writes the saved data out of RAM and back onto secondary storage. When you close the program, the operating system removes it from RAM, freeing that memory for another program. The direction matters: opening loads a program into RAM, while saving writes data back out of RAM.

ActionDirection of transferWhat the operating system does
Opening a programSecondary storage to RAMLoads the program and any files it needs into RAM
Saving workRAM to secondary storageWrites the saved data back out of RAM onto secondary storage
Closing a programRemoved from RAMClears the program out of RAM so the space can be reused

RAM is limited, so the operating system has to share it carefully between all the programs that are open. Memory management is the operating system function that decides where each program and its data are placed in RAM: it allocates an area to a program that needs one, and frees that area when the program closes.

The operating system keeps a record of memory: which areas are in use, which program owns each area, and which areas are free. For example, on a laptop with a video call app open, the operating system itself sits in one area of RAM, the video call app sits in another, and a third area is still unclaimed.

Memory areaUsed byStatus
Area 1Operating systemIn use
Area 2Video call appIn use
Area 3NoneFree

Memory protection means each program's area is kept separate from every other program's. The operating system stops one program from writing into another program's memory area, so a program cannot overwrite another program's data, or read it and change it. If a program crashes, the operating system can stop it without damaging other programs, because their memory areas are separate.

When a program closes, the memory it was using is freed, and that area can then be allocated to another program. Holding each program in its own protected area is what makes multitasking work safely: several applications sit in RAM at the same time, each in its own space, and none can interfere with another.

Memory management is one job of an operating system, and it works with RAM: which programs and data are held in memory, where each running program's area of memory is, and when that memory can be freed. A task has to be matched to the function that really does that job, and the clue is what each function works with.

Operating system functionWhat it works with
Memory managementRAM, and the programs and data held in it
Peripheral managementInput and output devices
User managementUser accounts and access rights
File managementFiles and folders in storage
User interfaceHow you see and control the computer

Multitasking is part of memory management: holding several programs in RAM at once only works if each one is kept in its own area there. A task is memory management when the operating system is deciding what sits in RAM and where, even if a device or a file is involved somewhere in the job.

Worked example: a pupil starts exporting a video in a media editor and then opens a spreadsheet to log the results. Each program sits in its own area of RAM, so the export carries on while the spreadsheet is used. The task here is memory management, because the operating system is working with RAM and the programs inside it, not with a device, an account or a file.

Also useful