995 views

1 Answer

1 votes
1 votes

Well, although the both seem to be dividing memory into parts, but their lies a difference in the way (and in situations) they are useful.

Overlays:

Overlaying is a programming method that allows programs to be larger than the computer's main memory. This larger memory is achieved by programmer manually specifying what should be present in memory at a particular instance of time. Thus a programmer can write 10 overlays of 512KB and choose that at a time only two overlays be present.

A real word example can be, consider a space shuttle program. It may have a launcher module code, mid-air module code.. etc. These can be thought of as overlays - LauncherOverlay, MidAirOverlay etc. Since memory is critical in space shuttle (and so is the processing speed), programmer would specify LauncherOverlay to be in memory. Once launch has taken place, we would no longer need LauncherOverlay, so now programmer can specify MidAirOverlay to be in memory. 

Because only one (or few) of them is in memory at a time, there is no need to MMU (Memory Management Unit which translates virtual address to physical address). So, even without using Virtual address (space), programmer is able to program using larger memory. This results in speed too.

Segments:

Well, they too are used to divide the code in to various parts called segments, but they are usually used for keeping the memory address spaces separate. Like StackSegment, CodeSegment, DataSegment etc. But why would we need address spaces to be different. This is because a in linear address space, if we divide the memory into parts mentioned above, then we would have to specify a maximum space which a certain part can take. 

Example can be to consider a memory from address 0 to 99.  if a StackSegment is from address 0 to 20, CodeSegment from 21 to 45 etc, then these cannot grow beyond address mentioned. But what if at runtime, a process needs more memory ? it is not always possible to know this in advance. 

So we want address spaces to be linearly independent i.e. all segments would start from address 0 whether it is StackSegment or CodeSegment or any other. These segments would then be loaded to separate spaces. So these can grow (and shrink) independently. 

Also segments are used to enable sharing portions of memory - a key distinction from overlays.

Related questions

0 votes
0 votes
1 answer
1
1 votes
1 votes
1 answer
2
1 votes
1 votes
7 answers
4
sh!va asked Dec 6, 2016
1,480 views
Conceptual question:What is the difference between program and process?any simple ,clear answer plz..