1. Introduction

In traditional program execution, the entire program and all required libraries are loaded and linked before execution begins. While this approach is simple, it is often inefficient because many parts of a program may never be used during a particular execution.

This leads to several problems:

  • Increased memory consumption

  • Larger executable files

  • Longer program startup time

  • Wasted system resources

To address these issues, modern operating systems use two important techniques:

  • Dynamic Loading

  • Dynamic Linking

These techniques improve memory utilization, reduce redundancy, and increase execution flexibility.

2. Dynamic Loading

2.1 Definition

Dynamic Loading is a technique in which a program module is loaded into memory only when it is required during execution.

Instead of loading the entire program into memory at startup, individual modules are loaded on demand.

2.2 Core Idea

The basic idea behind dynamic loading is:

  • Divide a program into multiple modules

  • Keep rarely used modules on disk

  • Load modules only when they are needed

This reduces the amount of memory occupied by the program.

2.3 Why Dynamic Loading is Needed

In many programs:

  • Some functions are rarely executed

  • Error-handling routines may never be called

  • Optional features may remain unused

Loading all modules in advance wastes memory.

Dynamic loading ensures that memory is allocated only when required.

2.4 Working Mechanism

The execution process typically follows these steps:

Step 1

The main program is loaded into memory.

Step 2

Program execution begins.

Step 3

A function or module is invoked.

Step 4

The operating system checks whether the module is already present in memory.

Step 5

If the module is not loaded:

  • The module is fetched from disk

  • Loaded into memory

Step 6

Execution continues normally.

Flow of Dynamic Loading

Program Starts
      ↓
Main Module Loaded
      ↓
Function Call Occurs
      ↓
Module Present?
   ↙       ↘
 Yes       No
  ↓         ↓
Execute   Load Module
              ↓
          Execute

2.5 Example

Consider a compiler program.

Main Program
      ↓
Parse Source Code
      ↓
Generate Object Code
      ↓
Error Handler

The error-handling module may never execute if no errors occur.

Instead of loading it initially:

Main Program Running
       ↓
Error Occurs
       ↓
Load Error Module
       ↓
Handle Error

This saves memory during normal execution.

2.6 Advantages

Reduced Memory Usage

Only required modules occupy memory.

Faster Startup Time

Less code needs to be loaded initially.

Better Memory Utilization

Unused modules remain on disk.

Supports Large Programs

Programs larger than available memory can be managed efficiently.

2.7 Disadvantages

Loading Delay

First access to a module may introduce a small delay.

Additional Complexity

Program must be designed to support dynamic loading.

Runtime Overhead

The system must check whether modules are already loaded.

3. Dynamic Linking

3.1 Definition

Dynamic Linking is a technique in which external libraries are linked to a program during execution rather than during compilation.

Instead of including library code inside every executable, programs share common library files.

3.2 Core Idea

The basic idea is:

  • Store library code separately

  • Share it among multiple programs

  • Link to it only when needed

This reduces duplication of code.

3.3 Why Dynamic Linking is Needed

Many applications use the same libraries.

Examples:

  • Standard C Library

  • Graphics Libraries

  • Networking Libraries

  • Database Libraries

Without dynamic linking:

Every executable would contain its own copy of the library.

This causes:

  • Larger executables

  • Wasted memory

  • Code duplication

Dynamic linking solves these problems.

3.4 Working Mechanism

Step 1

Program contains references to library functions.

Step 2

Program starts execution.

Step 3

Library function is called.

Step 4

The operating system checks whether the library is already loaded.

Step 5

If not loaded:

  • Library is loaded into memory

Step 6

Function references are resolved.

Step 7

Function executes normally.

Flow of Dynamic Linking

Program Starts
      ↓
Library Function Called
      ↓
Library Loaded?
   ↙       ↘
 Yes       No
  ↓         ↓
Execute   Load Library
              ↓
          Resolve References
              ↓
            Execute

3.5 Example

Consider the C statement:

printf("Hello World");

The function printf() belongs to the standard C library.

With dynamic linking:

Program
   ↓
Calls printf()
   ↓
Shared Library Loaded
   ↓
printf() Executes

The library code is not duplicated inside every executable.

3.6 Shared Libraries

Dynamic linking commonly uses shared libraries.

Examples:

Windows

.dll
(Dynamic Link Library)

Linux

.so
(Shared Object)

macOS

.dylib
(Dynamic Library)

Multiple programs can use the same library simultaneously.

3.7 Advantages

Reduced Memory Usage

Multiple processes share one copy of the library.

Smaller Executables

Library code is not embedded in each program.

Easier Updates

Updating a library automatically benefits all programs.

Better Resource Utilization

Reduces duplication across the system.

3.8 Disadvantages

Runtime Overhead

Linking occurs during execution.

Dependency Problems

Programs may fail if required libraries are missing.

Version Compatibility Issues

Different library versions may create conflicts.

4. Dynamic Loading vs Dynamic Linking

FeatureDynamic LoadingDynamic Linking
PurposeLoad program modulesLink external libraries
FocusProgram code segmentsShared libraries
OccursDuring executionDuring execution
Memory SavingWithin a programAcross multiple programs
Main BenefitLoad only required modulesShare common libraries

Key Insight

Dynamic loading optimizes memory usage inside a single program.

Dynamic linking optimizes memory usage across multiple programs.

5. Static vs Dynamic Linking

Static Linking

In static linking:

  • Library code is copied into the executable

  • Linking occurs before execution

Characteristics

  • Larger executable size

  • No external dependencies

  • Faster execution startup

Dynamic Linking

In dynamic linking:

  • Library code remains separate

  • Linking occurs at runtime

Characteristics

  • Smaller executable size

  • Shared libraries

  • More flexible updates

Comparison

FeatureStatic LinkingDynamic Linking
Linking TimeCompile TimeRuntime
Executable SizeLargeSmall
Memory UsageHighLow
Library SharingNoYes
UpdatesRecompile RequiredAutomatic
FlexibilityLowHigh

6. Relationship Between Dynamic Loading and Dynamic Linking

Although the two concepts are related, they solve different problems.

Dynamic Loading

Focuses on:

Program Modules

Example:

Load Error Handler
Only When Needed

Dynamic Linking

Focuses on:

Shared Libraries

Example:

Use Shared printf()
Library

Both techniques may be used together in modern operating systems.

7. Practical Applications

Dynamic loading and dynamic linking are used extensively in modern software systems.

Shared Libraries

.dll
.so
.dylib

Web Browsers

Browser modules loaded on demand.

Integrated Development Environments (IDEs)

Features loaded only when required.

Games

Maps, textures, and assets loaded dynamically.

Plugin Systems

Examples:

  • Photoshop Plugins

  • Browser Extensions

  • IDE Extensions

Operating Systems

Device drivers can be loaded dynamically.

8. System-Level Impact

These techniques provide several system-wide benefits:

Improved Scalability

More programs can execute simultaneously.

Reduced Memory Consumption

Unused code remains on disk.

Faster Application Deployment

Smaller executables are easier to distribute.

Better Resource Sharing

Common libraries are reused across applications.

Reduced Redundancy

Avoids storing duplicate copies of the same code.

9. Real-World Analogy

Consider a university library.

Dynamic Loading

You borrow a book only when you need it.

Need Book
    ↓
Borrow Book
    ↓
Use Book

You do not carry every book from the library at all times.

Dynamic Linking

Instead of every student buying a copy of the same textbook:

One Library Copy
        ↓
Many Students Use It

This is exactly how shared libraries work.

10. Exam-Oriented Summary

Dynamic Loading

  • Loads modules only when needed

  • Saves memory

  • Reduces startup time

  • Module-focused optimization

Dynamic Linking

  • Links libraries at runtime

  • Enables library sharing

  • Reduces executable size

  • System-wide memory optimization

Dynamic Loading vs Dynamic Linking

Dynamic LoadingDynamic Linking
Loads modulesLinks libraries
Program-level optimizationSystem-level optimization
Saves memory within programSaves memory across programs

Most Important Point

Dynamic Loading reduces memory usage within a program, while Dynamic Linking reduces memory usage across multiple programs through shared libraries.