Segmentation (static)

The concept of segmentation is based on the common practice by programmers of structuring their programs in modules-logical groupings of code. With segmented memory allocation, each job is divided into several segments of different sizes, one for each module which contains pieces that perform related functions. A subroutine is an example of one such logical group. This is fundamentally different from a paging scheme, which divides the job into several pages all of the same size each of which often contains pieces from more than one program module.

A second important difference is that main memory is no longer divided into page

frames because the size of each segment is different - some are large and some are small. Therefore, as with the dynamic partitions , memory is allocated in a dynamic manner.

When a program is compiled or assembled, the segments are set up according to the program's structural modules. Each segment is numbered and a Segment Map Table (SMT) is generated for each job - it contains the segment numbers, their lengths, and (when each is loaded into memory) its location in memory.

 

 


The system maintains three tables:

 

1.The job table (as with static paging)

2.The segment Map table list details about each job (one for each job)

3.Memory Map Table (as before).

 

 

 

Like paging, the instructions within each segment are ordered sequentially, but the segments need not be contiguous in memory. We only need to know where each segment is stored. The contents of the segments themselves are contiguous (in this scheme). To access a specific location within a segment we can perform an operation similar to the one used with paged memory management. The only difference is that we work with segments instead of pages.

 

The addressing scheme requires the segment number and the displacement within that segment, and, because the segments are of different sizes, the displacement must be verified to make sure it isn't outside of the segment's range.

 

 

A segmented address reference requires the following steps:

1. extract the segment number and the displacement from the logical address

2. use the segment number to index the segment table, to obtain the segment base address and length.

3. check that the offset is not greater than the given length; if so an invalid address is signaled.

4. generate the required physical address by adding the offset to the base address.

 

 
 

 

Main Points:

 

The benefits of segmentation include modularity of programs and sharing and protection.

 

There is a maximum segment size that the programmer must be aware of.

 

No internal fragmentation

 

Unequal sized segments

 

Non –contiguous memory.

 

Some external fragmentation.

 

 

Segmentation greatly facilitates the sharing of procedures or data between a number of processes. Because a segment normally has either program code or data within them different segments within the same process can have different protections set for them. While protection is possible in a paging environment it is far more difficult to implement, the programmer is unaware of what pages hold a procedure or data area that he may wish to share, to do this the programmer would have to keep track of the exact pages that held a procedure and then assign the necessary protection to those pages.