On 2/23/2006 at 3:09 PM Liam Proven wrote:
So. What is a segment, what is a page, and what is the
difference? I
know that pre-386 Intel x86 chips used a 64k segment size and that
this caused problems, but little more than that.
We're suffering a bit from nomenclature problems.
Generally speaking, paging consists of dividing addressing space up into
equally-sized chunks of memory, and swapping these chunks of memory from a
secondary store. Optimization (i.e. making sure that related pages are in
primary memory at the same time) is left to the operating system (hence,
you'll see terms like "demand paging" (basically dumb paging) or
"working
set paging" (an attempt to predict the behavior of a program based on its
history)).
Segmentation operates at a higher level. A segment may represent all or
part of a DLL or data structure--in other words, contents of a segment are
more likely to be related. Segments are not usually of equal size. Since
a segment is swapped in as unit, contiguous physical memory must be
available for it--hence Windows insistence on using handles for memory
allocation (the implication is that things can move). Consider a segment
to be a chapter in a book--it's a logical entity.
In general, a well-designed program operating in segmented mode has the
potential of swapping less than one that is paged. However, paging frees
the programmer from worrying about organizing things in segmented fashion
(and having to deal with selectors)--what is seen is simply a huge linear
address space (Usually CS=DS=ES=FS=GS and nobody changes them).
But when we talk about segmentation, don't confuse this with Intel's
unfortunate labeling of CS DS ES FS and GS as "segment" registers in real
mode. That was a bad name for them--better to have called them "paragraph
registers". In fact, when you get into 286 segmented mode, Intel calls
them "selectors", not segment registers. Yes, in 286 segmented mode, the
size of a segment is limited to 64K, but that's because the segment length
field is 16 bits. Segments can be smaller than 64K.
Cheers,
Chuck