1. LPU MCA Semester 1
  2. CAP366
  3. Unit 7

CAP366 · Unit 7: Memory management

Dynamic loading and linking, overlays, swapping

10 practice questions · in the ETE syllabus

Key points

  • Dynamic loading: load a routine when first called
  • Dynamic linking uses a stub and allows shared libraries
  • Overlays keep only needed sections resident
  • Swap time = transfer + latency, counted both ways for out and in

Dynamic loading loads a routine into memory only when it is first called, so unused routines never occupy memory. Static linking copies library code into every executable; dynamic linking postpones linking to run time, using a stub that locates the routine, and lets many processes share a single copy of a library.

Overlays let a program larger than its allotted memory run by keeping only the currently needed section resident and loading other sections over it; the programmer designs the overlays and an overlay driver loads them. Example: a two-pass assembler with pass 1 = 70 KB, pass 2 = 80 KB, symbol table 30 KB, common routines 20 KB and driver 10 KB needs 30 + 20 + 10 + 80 = 140 KB with overlays.

Swapping temporarily moves a whole process between main memory and a backing store. Swap time is dominated by transfer time plus latency: a 10 MB process at 40 MB/s with 8 ms latency takes 250 + 8 = 258 ms each way, so 516 ms for out and in. A process with pending I/O into its own memory must not be swapped out carelessly, because the device would write into memory owned by someone else.

Exam trap: swapping moves entire processes, whereas paging moves fixed-size pages.

Try two questions

Question 1 · Tier 4, Analyse

A two-pass assembler has the sizes Pass 1 needs 70 KB, Pass 2 needs 80 KB, symbol table 30 KB, common routines 20 KB, and an overlay driver of 10 KB. What is the minimum memory with overlays?

  1. 210 KB
  2. 150 KB
  3. 140 KB
  4. 130 KB
Show the answer

C. The two passes are never needed together, so memory is symbol table + common + driver + the larger pass: 30 + 20 + 10 + 80 = 140 KB.

Why not A: 210 KB keeps both passes resident together with everything else.

Why not B: 150 KB counts the 10 KB overlay driver twice.

Why not D: 130 KB sizes the overlay for the smaller pass, which cannot hold Pass 2.

Question 2 · Tier 3, Apply

A program has a main routine of 100 KB and six routines of 50 KB each, and during one run it calls only two of the six routines. How much memory does it need with dynamic loading?

  1. 200 KB
  2. 400 KB
  3. 300 KB
  4. 250 KB
Show the answer

A. Only the main routine and the two called routines are loaded: 100 + 50 + 50 = 200 KB.

Why not B: That is the total if the main routine and all six routines are loaded.

Why not C: That would be the main routine plus four routines rather than two.

Why not D: That would be the main routine plus three routines rather than two.