Paging
• Fixed-size blocks (typically 4KB)
• Eliminates external fragmentation
• Allows non-contiguous memory allocation
• Uses page tables to track memory locations
Segmentation
• Variable-sized segments based on program logic
• Each segment has a name and length
• Can lead to external fragmentation
• More intuitive for programmers (reflects code structure)
Virtual Memory
• Programs can be larger than physical RAM
• Multiple programs can run simultaneously
• Isolation between processes (security)
• Efficient memory utilisation
Virtual Memory Downsides:
• Slower than physical RAM (disk access)
• Disk thrashing can occur if overused
Disk Thrashing
Paging and Segmentation Compared
| Feature | Paging | Segmentation |
|---|---|---|
| Size of the blocks | Fixed size (pages) | Variable size (segments) |
| How memory is divided | Physically, taking no account of how the program is structured | Logically, each segment matching a part of the program such as a subroutine or data structure |
| Fragmentation | Internal: the last page of a program may not be full | External: gaps are left between segments that may be too small to use |
Both methods let a program be stored in parts that are not next to each other in memory, and both let the parts that are not in use be moved to virtual memory.
• Allocates RAM to each program and frees it when it is no longer needed
• Stops a program from accessing memory allocated to another program, which keeps data secure
• Moves pages that are not currently needed out to virtual memory when RAM is nearly full, and back again when they are required