hello friends,
I want to ask what do you call by the term called memory segmentation in the computer world ? Is it useful ? If yes, then how do I segment the memory ? Can anybody provide some useful information regarding the same....
thank you
Printable View
hello friends,
I want to ask what do you call by the term called memory segmentation in the computer world ? Is it useful ? If yes, then how do I segment the memory ? Can anybody provide some useful information regarding the same....
thank you
In memory segmentation, memory is divided into portions that may be addressed by a single index register without changing a 16-bit segment selector. Each portion is called as segment.
In real mode or V86 mode, a segment is always 64 kilobytes in size (using 16-bit offsets).
In protected mode, a segment can have variable length.
Memory Segmentation
In computing, memory segmentation is one of the most common ways to achieve memory protection; another common one is paging. Using segmentation, an instruction operand that refers to a memory location includes a value that identifies a segment and an offset within that segment. A segment has a set of permissions, and a length, associated with it. If the currently running process is allowed by the permissions to make the type of reference to memory that it is attempting to make, and the offset within the segment is within the range specified by the length of the segment, the reference is permitted; otherwise, a hardware exception is raised.
In addition to the set of permissions and length, a segment also has associated with it information indicating where the segment is located in memory. It may also have a flag indicating whether the segment is present in main memory or not; if the segment is not present in main memory, an exception is raised, and the operating system will read the segment into memory from secondary storage. The information indicating where the segment is located in memory might be the address of the first location in the segment, or might be the address of a page table for the segment, if the segmentation is implemented with paging. In the first case, if a reference to a location within a segment is made, the offset within the segment will be added to address of the first location in the segment to give the address in memory of the referred-to item; in the second case, the offset of the segment is translated to a memory address using the page table.
In a segmented memory management system the blocks to be replaced in main memory are potentially of unequal length and correspond to program and data ``segments.'' A program segment might be, for example, a subroutine or procedure. A data segment might be a data structure or an array. In both cases, segments correspond to logical blocks of code or data. Segments, then, are ``atomic,'' in the sense that either the whole segment should be in main memory, or none of the segment should be there. The segments may be placed anywhere in main memory, but the instructions or data in one segment should be contiguous.
A segmented memory organization
-----------
SEGMENT 1
-----------
SEGMENT 5
-----------
SEGMENT 7
-----------
SEGMENT 2
-----------
SEGMENT 4
-----------
SEGMENT 9
-----------
Using segmented memory management, the memory controller needs to know where in physical memory is the start and the end of each segment. When segments are replaced, a single segment can only be replaced by a segment of the same size, or by a smaller segment. After a time this results in a "memory fragmentation'', with many small segments residing in memory, having small gaps between them. Because the probability that two adjacent segments can be replaced simultaneously is quite low, large segments may not get a chance to be placed in memory very often. In systems with segmented memory management, segments are often ``pushed together'' occasionally to limit the amount of fragmentation and allow large segments to be loaded.
This organization appears to be efficient because an entire block of code is available to the processor. Also, it is easy for two processes to share the same code in a segmented memory system; if the same procedure is used by two processes concurrently, there need only be a single copy of the code segment in memory. (Each process would maintain its own, distinct data segment for the code to access, however.)
Segmented memory management is not as popular as paged memory management, however. In fact, most processors which presently claim to support segmented memory management actually support a hybrid of paged and segmented memory management, where the segments consist of multiples of fixed size blocks.