Definition: Memory segmentation is the process in which we divide the primary memory of the computer into segments. It is a memory management technique. Each segment can be allocated to a process.
The segment table is the table which stores all the details about the segments which are further stored in one of the segments. Segment table contains two information about the segment: one is, the base address of the segment and other is, the length of the segment.
We’ll be covering the following topics in this tutorial:
Need of Segmentation
Before segmentation, we use paging as our memory management technique as paging is more close to the operating system instead of the user. Paging decreases the efficiency of the system as it can divide the same function into different pages which may or may not be loaded into the memory at the same time. On the other hand, segmentation divides the process into segments, and each segment can contain the same type of functions.
Difference Between Paging and Segmentation
|Paging is closer to our operating system.||Segmentation is closer to the user rather than the operating system.|
|There is no need of doing any external fragmentation.||There is external fragmentation in segmentation.|
|In this, the page information is stored in the page table.||In this, the information about segments is stored in the segment table.|
|In this, our operating system is responsible.||In this, the compiler is responsible for the working.|
|Paging suffers from internal fragmentation instead of external fragmentation.||Segmentation suffers from external fragmentation rather than internal fragmentation.|
|Paging divides our program into various fixed size pages.||Segmentation divides our program into various variable size segments.|
|In this, the logical address is divided into two things; page number and page offset.||In this, the logical address is divided into two things: segment number and segment offset.|
|Paging is faster than segmentation.||Segmentation is slower than paging.|
|It is a non-contiguous memory allocation.||It is a non-contiguous memory allocation.|
|The entry of the page table contains flag bits and frame number so that it can represent the details about the pages.||On the other hand, the entry of segment table contains base address and some protection bits of the segments.|
Translation of logical address into physical address by the segmentation
A logical address is generated by the CPU which consists of two things:
1. Segment number
The segment number which logical address contains is mapped into the segment table. Now we compare the limit of the segment with the offset. If the respective limit is more than the offset, then there will be valid address otherwise the address will be invalid. When the address in invalid, then it will show an error. Through this, we get the physical address of the real word which is stored in the main memory.
All of this is wholly explained through the diagram given below. You can refer to this figure as well.
Advantages of Memory Segmentation
• There is less overhead in segmentation.
• There is no internal fragmentation as external fragmentation is done in this.
• The size of the segment table is less whereas the size of the page table is big in paging.
• The average size of the segment is more as compared to the actual size of the page.
• We can easily relocate the segments as compared to the address space.
Disadvantages of Memory Segmentation
• It is a costly technique as compared to the other one.
• External fragmentation is there in it.
• Since there is a variably sized partition. So, it is difficult to allocate memory to them.