Difference Between Demand Paging and Segmentation

Demand Paging and Segmentation are memory management techniques in operating systems, each with a unique approach to handling memory. Demand Paging loads only the required pages of a program into memory on demand, reducing memory usage and allowing programs to run even if all pages aren’t loaded, using virtual memory concepts. Segmentation, however, divides a program into logical segments like code, data, and stack, which are loaded into memory as needed, providing a more organized memory structure based on program components.

What is Demand Paging?

Demand paging is a memory management scheme that loads pages into physical memory only when they are needed, rather than loading the entire program into memory at once. This technique helps in utilizing memory efficiently and allows for handling larger programs or data sets with limited physical memory.

Examples of Demand Paging:

  1. A web browser loading only the portions of a website that are currently viewed by the user.
  2. An operating system loading only the necessary pages of a large application when specific features are accessed.

What is Segmentation?

Segmentation is a memory management technique that divides the memory into variable-sized segments based on logical units such as functions, data structures, or user-defined modules. Each segment is independently managed and allocated memory, making it easier to handle programs with different types of data and code.

Examples of Segmentation:

  1. A word processor might segment memory into separate segments for the text editor, formatting tools, and spell check functions.
  2. A compiler might use segmentation to separate code segments, data segments, and stack segments.

Difference Between Demand Paging and Segmentation:

BasisDemand PagingSegmentation
DefinitionLoads pages into memory only when they are needed.Divides memory into variable-sized segments based on logical units.
Memory AllocationPage-based, where memory is divided into fixed-size blocks (pages).Segment-based, where memory is divided into segments of varying sizes.
Page Fault HandlingHandles page faults by loading the required page from disk into memory.Handles segment faults by loading the required segment from storage.
FlexibilityFixed-size pages provide less flexibility in managing memory for different data sizes.Variable-sized segments offer more flexibility and can accommodate different sizes of data and code.
FragmentationCan lead to internal fragmentation if allocated pages are not fully used.Can lead to external fragmentation as segments may leave gaps in memory.
ExamplesOperating systems using virtual memory to manage applications.Applications organized into logical modules or data structures.
tools

Operating Systems

Related Articles