Memory Management (OCR A Level Computer Science)

Revision Note

Callum Davies

Written by: Callum Davies

Reviewed by: James Woodhouse

Memory Management

What is Memory Management?

  • Memory management is a fundamental role of the operating system, dealing with the allocation and deallocation of the computer's primary memory

  • When a user opens an application, its data is loaded from storage into active memory so that it can run smoothly

  • When a user opens a file from the file system, e.g. word document, the CPU loads this file data, as well as application data, into the primary memory

  • Primary memory is a limited resource in the system, so it needs careful management

  • Benefits of memory management are:

    • Efficient allocation of memory enables multitasking, allowing multiple programs to run at once

    • Memory management maintains security, it does not let programs access memory reserved for other programs

  • Memory management is made more efficient through 3 techniques:

    • Paging

    • Segmentation

    • Virtual Memory

Links between different types of memory and memory management

Links between different types of memory

Examiner Tips and Tricks

  • The main benefit of memory management is to make computer systems run smoothly. Most users don’t realise that as they effortlessly move between applications, it’s made possible because the OS is rapidly reallocating memory depending on the task that the user is completing.

  • Make sure you can name one benefit and one drawback for each memory management method in this revision note.

Paging

What is Paging?

  • Data stored in memory will lead to the smooth running of applications

  • Paging is a method of chunking the primary memory into equal-sized blocks

  • When an application is launched, data will be moved from the hard disk into Pages for faster access

  • As users move between applications, memory is dynamically allocated

  • Pages will be taken away from applications not in active use and granted to applications that are in active use

  • Paging can lead to internal fragmentation

  • If a 200KB file is divided into four 64KB Pages, the last Page would have 8KB of unused space

  • Unused space in a Page is wasteful because other unrelated data cannot be stored in this Page

  • Over time, more pockets of wasted space will exist across the memory; this process is called internal fragmentation

  • The image below shows a single 64KB Page with 4KB of unoccupied space

  • The box below this shows many Pages, each with varying sizes of internal fragments

Internal fragmentation

Internal fragmentation

Segmentation

What is Segmentation?

  • Segmentation is a method of chunking memory into blocks that correspond to different types of data needed by an application

  • A video editing application may have a Segment for video data, audio data and special effects

  • Segments are not all the same size; they are sized depending on their allocated data

  • Segmentation is space-efficient due to only allocating space depending on the amount an application needs

  • Segmentation can lead to external fragmentation

  • As Segments fill up the memory, physical gaps reduce the maximum size of new Segments that can be allocated

  • Below (left) shows different application data assigned to a Segment

  • The arrangement of data in the segment becomes more fragmented over time because as blocks are taken away it's not possible to guarantee a new block will occupy the same amount of space

  • Below (right) shows a defragmented version of the Segment to highlight the total unused space

segmentation-external-fragmentation-alevel

External fragmentation

Virtual Memory

Virtual Memory

  • If a computer is running low on primary memory, it can make secondary storage act as an 'extension' of the main memory

  • The operating system can offload data from the primary memory into virtual memory

  • Virtual memory creates an illusion of a larger memory and enables applications to continue to multitask

  • However, accessing data in virtual memory is considerably slower compared to RAM

  • Solid-state drives are faster than traditional hard-disk drives, but neither are as fast as RAM 

  • Over-reliance on virtual memory can lead to performance issues

Memory Management Technique

Description

Example

Benefits

Drawbacks

Paging

Divides memory into fixed-sized blocks (pages)

A process needing 200KB of memory is divided into four 64KB pages, leaving 8KB unused in the last page

Facilitates efficient memory management and enables the use of virtual memory

This can lead to internal fragmentation

Segmentation

Divides memory into variable-sized segments based on logical parts of a process

In a video editing application, different segments may be created for video data, audio data, effects, and UI elements

Allows for intuitive and efficient memory access

This can result in external fragmentation

Virtual Memory

Uses hard drive space as an 'extension' of RAM

When memory-intensive applications exceed the available RAM, the OS moves less frequently accessed pages to the hard disk

Allows more extensive programs to be run and facilitates effective multitasking

Slower to access than physical memory, which degrades performance if overused

Examiner Tips and Tricks

  • Virtual memory is a method of memory management.

    • Not to be confused with Virtual Storage, which is storing files in the cloud.

Worked Example

Describe how the operating system would use virtual memory to load program C when there's not enough space in physical memory.

[3]

Answer:

 Answer that gets full marks:

The operating system can use virtual memory to act as an extension of the computer's primary memory. This means less-critical data can be offloaded from the primary memory into virtual storage, useful when a higher-priority set of processes require immediate attention. If the OS offloaded data from the RAM into virtual memory, this would free up space for program C to be loaded into RAM.

Acceptable answers you could have given instead:

Program C can be loaded into the RAM if the operating system moves files and data into virtual memory. Virtual memory acts as an extension of the RAM.

Worked Example

Imogen buys a desktop computer. It comes with an operating system installed.

Describe two ways that an operating system could manage physical memory.

[4]

How to answer this question

  • Recall two methods of memory management (Paging, segmentation, virtual memory)

  • Explain how each of these works and how they assist in memory management

Answer:

 Example answer that gets full marks:

Imogen's operating system could manage physical memory in two ways. Paging, which is a method of dividing memory into fixed-size chunks known as pages. Application data can be allocated and deallocated to pages making it a flexible system depending on the activity of the user.

The system could also use virtual memory, a method of extending the available physical memory by using a portion of the hard drive. This allows more programs to run simultaneously and enhances the overall system performance.

Acceptable answers you could have given instead:

Imogen's computer uses paging to manage memory. This means it breaks down the memory into fixed-size pieces and swaps them in and out as needed.

The computer also uses something called virtual memory. It uses part of the hard drive to act like extra memory, so more programs can run at the same time, and everything works faster.

Last updated:

You've read 0 of your 5 free revision notes this week

Sign up now. It’s free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Callum Davies

Author: Callum Davies

Expertise: Computer Science

Callum is an experienced teacher of GCSE and A-Level Computer Science. He has 4 years of teaching experience and has detailed knowledge of how to achieve exam success, having marked for OCR A-Level. Callum is now a software engineer and regularly mentors new engineers.

James Woodhouse

Author: James Woodhouse

Expertise: Computer Science

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.