🎓 BookMCQ
← Back to 8. Main Memory

📝 Dynamic memory loading in Main memory (9 MCQs)

Bringing Program Routines into Memory When Required

Dynamic loading is a memory-management technique in which a program routine enters main memory only when execution first requires it. An executable can contain routines that remain on secondary storage until called. This arrangement reduces the memory occupied by infrequently used code, particularly in large applications containing optional features, error-handling routines, specialised reports, or alternative processing modules.

Why Selective Routine Loading Reduces Memory Waste

Loading every routine before execution can consume valuable RAM even when some functions are never called. Applications containing extensive libraries, optional reports, and alternative processing paths may include substantial inactive code. Dynamic loading addresses this problem by postponing the loading of unused routines. It is especially helpful when memory capacity is limited or several large applications execute concurrently.

Procedure for Loading a Routine on First Use

The program begins execution with its initially required routines available in memory. When execution reaches an unloaded routine, a calling mechanism checks its availability and requests loading from the executable or another storage location. The routine is placed into an appropriate memory region, and execution transfers to it. Subsequent calls can reuse the loaded routine without repeating its initial loading operation.

Loading an Infrequently Used Reporting Module

Consider a 20 MB application containing a 5 MB reporting routine that only some users need. Without dynamic loading, all 25 MB of code may need to be available. With dynamic loading, the reporting routine remains on storage until requested. A user who never opens reports avoids bringing that additional 5 MB of code into memory.

Memory Savings and the Cost of First Access

Dynamic loading reduces memory consumption and can allow more applications to remain active, improving resource utilisation. Its disadvantage is the delay involved in bringing a routine into memory on first use, particularly when storage access is slow. The technique depends on appropriate program organisation and loading support. It should not be confused with dynamic linking, which resolves external program references.

Distinguishing Routine Loading from Linking

'Dynamic loading means allocating heap memory at runtime' is incorrect because it concerns bringing executable routines into memory. 'Every routine is loaded when the process starts' is incorrect because unused routines can remain on storage. 'Dynamic loading automatically resolves shared-library symbols' is incorrect because symbol resolution belongs to linking and dynamic-library mechanisms.

Exam Focus: First-Call Loading and Memory Savings

Identify which routines remain outside main memory until called and explain how the first invocation triggers loading. Calculate potential memory savings by comparing total program size with the routines actually required. Questions may contrast dynamic loading with static loading, dynamic linking, and demand paging. Remember that dynamic loading is a program-level strategy rather than a specific page-replacement algorithm.

Key Terms of Dynamic Loading

  • Routine - Executable unit performing a task.
  • Dynamic loading - Loads routines when required.
  • Loader - Places executable code in memory.
  • First invocation - Initial call triggering loading.
  • Secondary storage - Holds unloaded routines.
  • Memory footprint - Memory occupied by a program.
2
Easy
4
Medium
3
Hard

📝 All Dynamic memory loading in Main memory MCQs

Q1. What is dynamic loading?

A.It loads code into memory only when a function is called for the first time ✅
B.It preloads all code at program start
C.It stores code on disk permanently
D.It compiles code during execution
💡 Difficulty: easy | ✅ Correct: A

📖 Explanation: Dynamic loading is a technique where the operating system brings a module into RAM only when the program first needs it. Option A describes this behavior. Option B describes static loading, which loads everything at start. Option C is unrelated to loading, and Option D confuses compilation with loading. Understanding this definition helps students recognize why programs can start faster and use less memory.

Q2. Why does dynamic loading typically improve memory utilization compared to static linking?

A.Because unused code remains on disk and never occupies RAM
B.Because it compresses code before loading ✅
C.Because it replaces physical memory with virtual memory
D.Because it merges multiple processes into one address space
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Dynamic loading keeps code that a program never calls on disk, so only the needed portions occupy RAM. Option B correctly states that only required code is loaded, reducing RAM usage. Option A is partially true but does not explain the mechanism. Options C and D describe unrelated concepts. Recognizing this benefit explains why many modern applications prefer dynamic loading.

Q3. A graphics application can load a plug‑in at runtime to add new filters. Which step is essential for the plug‑in to become usable?

A.Compiling the plug‑in source code on the fly
B.Embedding the plug‑in binary into the main executable
C.Calling the operating system’s loader to map the plug‑in into the process address space ✅
D.Writing the plug‑in’s output to a log file
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The operating system’s loader must map the plug‑in’s binary into the running process, allowing the program to call its functions. Option C captures this essential step. Option A would require a JIT compiler, which is not typical for binary plug‑ins. Option B defeats the purpose of dynamic loading, and Option D is unrelated to loading. This scenario shows how dynamic loading enables extensibility without rebuilding the main program.

Q4. When a program requests a symbol from a shared library during dynamic loading, which component resolves the symbolic address to a physical memory location?

A.The CPU’s instruction decoder
B.The compiler’s optimizer
C.The dynamic linker/loader at runtime
D.The hard‑disk controller ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: During dynamic loading, the runtime dynamic linker/loader examines the library’s symbol table and patches the program’s references, turning symbolic names into actual memory addresses. Option D correctly identifies this component. The CPU decoder (A) works after addresses are known, the optimizer (B) runs at compile time, and the disk controller (C) merely moves data. Knowing the role of the dynamic linker clarifies how symbols become usable after load time.

Q5. How does dynamic linking relate to the concept of shared libraries?

A.Dynamic linking copies library code into each process’s memory ✅
B.Dynamic linking allows multiple processes to reference the same library code in memory
C.Dynamic linking removes the need for libraries altogether
D.Dynamic linking forces each process to load a unique version of the library
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Dynamic linking works hand‑in‑hand with shared libraries: the library remains a single copy in memory, and each process that loads it at runtime shares that copy. Option A correctly describes this relationship. Option B mistakenly suggests copying, which would waste memory. Options C and D are inaccurate. Understanding this link explains why shared libraries reduce overall memory consumption while still providing modular code.

Q6. A program statically links a 10 MB library but only uses 2 MB of its functions. If the same library is dynamically loaded, how much memory could be saved?

A.2 MB2\text{ MB}
B.8 MB8\text{ MB} ✅
C.10 MB10\text{ MB}
D.No memory is saved
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: When statically linked, the entire 10 MB library occupies RAM even if only 2 MB is needed. Dynamic loading brings in only the required 2 MB, leaving the remaining 8 MB on disk. Thus the saved memory is 10 MB−2 MB=8 MB10\text{ MB} - 2\text{ MB} = 8\text{ MB}. Option B reflects this calculation. Options A and C give incorrect amounts, and D ignores the benefit of dynamic loading. This calculation illustrates the tangible memory savings dynamic loading can provide.

Q7. During execution, a program crashes with a “cannot locate symbol X” error. Which situation most likely caused this?

A.The library containing X was never compiled
B.The dynamic loader failed to map the library into the process
C.The symbol X was renamed in the library after the program was built ✅
D.The CPU cache was full
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: A missing‑symbol error at runtime typically means the loader could not resolve the reference, often because the symbol name does not match (renamed) or the library was not loaded. Option C directly addresses a rename mismatch, which is the most common cause. Options A and B would cause compile‑time or load‑time failures, not a runtime symbol error. Option D is unrelated to symbol resolution. Recognizing the cause helps developers troubleshoot dynamic loading problems.

Q8. What is lazy binding in the context of dynamic loading, and how does it affect program startup time?

A.It binds all symbols before the program starts, increasing startup time
B.It delays binding of each symbol until its first use, reducing startup time ✅
C.It preloads all libraries into memory regardless of use
D.It disables dynamic linking entirely
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Lazy binding postpones the resolution of each external symbol until the first time the program actually calls it, which shortens the initial loading phase. Option B captures this behavior. Option A describes eager binding, which lengthens startup. Option C is unrelated to binding strategy, and Option D eliminates dynamic linking. Understanding lazy binding explains why some programs start quickly but may incur a small delay on first use of a function.

Q9. A program uses logical addresses while executing. When the operating system moves its code segment to a different physical frame, which type of address does the program continue to use?

A.Logical (virtual) addresses ✅
B.Physical addresses
C.Disk block addresses
D.Absolute addresses
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The program operates with logical (virtual) addresses; the OS translates them to physical frames via paging or segmentation. Even if the code moves to a new physical frame, the program still references logical addresses, and the hardware mapping updates transparently. Option A is correct. Physical, disk block, and absolute addresses are not exposed to the running program. This distinction shows why dynamic loading can relocate code without requiring changes in the program’s address references.

🔗 Related Topics (MCQs)