LearnViz CompSci
Home / Learn / Operating Systems / Segmentation

Intermediate Topic 28 of 51 Operating Systems

Segmentation

Dividing memory into logical variable-size units.

How it works

Segmentation divides a program's address space into logical segments such as code, data, stack and heap, each with its own base and limit. An address is a pair of segment number and offset, and hardware checks the offset against the limit and the permissions. Segments can differ in size, matching the programmer's view, and can be shared or protected independently.

Step-by-step walkthrough

  1. Memory is split into logical segments by purpose.
  2. An address is a segment number plus an offset.
  3. The segment table gives a base and a limit.
  4. An offset beyond the limit raises a fault, giving protection.
  5. Segments vary in size, so external fragmentation can occur.

Where it is used

Early systems and Intel x86 real and protected mode used segmentation; modern operating systems use mostly flat memory with paging, keeping segments for thread-local storage and privilege checks. It also appears conceptually in executable file layouts.

Common pitfall

Variable-size segments cause external fragmentation and need compaction. Allocating contiguous memory for a segment can fail even with enough total free memory. Segmentation faults today usually mean invalid memory access caused by null pointers or buffer overruns, not literal segments. Combine with paging, as in segmented paging, to get the benefits of both.

Where it fits in the course

Segmentation is topic 28 of 51 in Operating Systems, rated Intermediate. It follows Paging. The next topic is Virtual Memory.

Practice and explore

How to study this topic

  1. Read the explanation above and restate the definition in your own words.
  2. Open the interactive lesson and answer its mini quiz.
  3. Read the common pitfall, then write a short example that avoids it.
  4. Check your understanding in the Operating Systems quiz, and revisit the topic if you miss a question.

Frequently asked questions

What is Segmentation?
Dividing memory into logical variable-size units. It belongs to Operating Systems and is an intermediate-level topic.
Where do people use Segmentation?
Early systems and Intel x86 real and protected mode used segmentation; modern operating systems use mostly flat memory with paging, keeping segments for thread-local storage and privilege checks.
What is the most common mistake with Segmentation?
Variable-size segments cause external fragmentation and need compaction.
What should I learn before this topic?
Start with Paging, the topic just before it in Operating Systems.
How can I practice it?
Answer the mini quiz in the interactive lesson, then take the Operating Systems quiz.
Is Segmentation hard to learn?
It is an Intermediate topic. Be comfortable with the Beginner topics in this area first, then read the common pitfall carefully, since it is where most mistakes happen.
How long does it take to learn Segmentation?
Most learners can read the explanation and finish the interactive lesson in under an hour. Fluency comes from applying the idea, so plan a few short practice sessions with the quiz.
Which topics are related to Segmentation?
Paging, Virtual Memory, Memory Management are closely connected. The full list is in the related topics section of this page.
What should I study after Segmentation?
Continue with Virtual Memory, the next topic in Operating Systems.

Related topics