What Is the Difference Between Paging & Segmentation?

Save

Paging and segmentation both refer to ways of dividing up a computer's memory. Paging refers to physically dividing memory into small, equally sized sections to which data can be quickly written for storage. Segmentation refers to logically dividing memory into sections of various sizes, each section used for different functions.

Memory Segmentation

Segmentation refers to dividing a computer's memory into contiguous sections that can be assigned to different programs for different purposes.

For example, each application might have a code segment to store the instructions to the computer's processor and various data segments to store temporary calculation results and consulted data while the app is running.

Some segments -- like those accessing common libraries of code or operating system functionality -- can be accessed by multiple programs. For security's sake, the operating system can keep track of which apps have permission to read, write and run code in different segments of memory. When a program tries to access memory in a segment without permissions, that triggers a segmentation violation or segmentation fault error. Segments can be different sizes and can sometimes change in size as a program is running, depending on the program's needs.

When an application needs to access an area in memory to read or write data, it provides an identifier of the desired segment and the index of a particular memory location within that segment, rather than the physical position of the location in memory. If the app requests additional memory, the operating system provides it with virtual addresses in terms of segment identifiers and sizes, not actual physical addresses.

The operating system and the processor's memory management unit translate those virtual addresses into physical locations in memory. Since the application only keeps track of the segment identifiers and where information is stored within each of its segments -- not the physical location of the segment in memory -- the operating system can maximize efficiency by moving around the memory location of segments or even free space in memory by storing them temporarily on the hard drive when they're not being used without having to notify the individual programs.

Moving segments can be time-consuming, whether moving them in and out of memory or rearranging memory to maximize segment storage by eliminating gaps, and operating systems use various techniques to organize free areas of memory into segments for programs to use -- techniques that minimize the need for later reorganization.

Memory Paging

Paging refers to dividing a computer's memory into small, discrete chunks called pages, generally smaller than memory segments.

Like the pages in a book -- and unlike memory segments -- each page is always the same size. Consistency of size makes pages easy to arrange in memory without leaving gaps, as can occur when programs work with differently sized segments. The small size of pages allows their contents to be quickly written to a hard disk for storage and quickly accessed to be read.

When an application wants to access a particular section of memory, the operating system determines the page identified by a particular address and where that page is stored on the disk. To do this, the OS uses a page table, which has a record of the location for each page. Processors contain special hardware the OS uses to store page data and do these calculations efficiently.

Since segmentation is still useful for thinking about how memory is organized into areas for different programs and for different functionality, and paging is useful for efficiency, some operating systems use both techniques, so each memory address is contained within a segment, and each segment is itself divided into pages that are individually stored in memory or on disk.

Promoted By Zergnet

Comments

You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!