Introduction
Loading is the process of transferring an executable program from storage (disk) to main memory (RAM) for execution. It is a key function of the operating system (OS) and is managed by a loader.
When a program is compiled, it is stored on a disk in an executable format. Before execution, the OS loads it into memory, assigns it the necessary resources, and begins execution.
Types of Loaders
The loader is responsible for loading programs into memory. There are different types of loaders based on how and when a program is loaded:
1. Absolute Loader
The program is compiled with a fixed memory address.
The loader directly loads the program into that address in memory.
No address modification is required.
Example:
- The program is compiled to run at address 5000.
- The loader places it exactly at 5000 in memory.
Limitation : The program must always run at a fixed address, reducing flexibility.
2. Relocatable Loader
The program can be loaded at any memory location.
The loader modifies addresses dynamically before execution.
Supports multiprogramming and dynamic memory allocation.
Example:
- The program assumes it starts at 0 during compilation.
- The OS decides to load it at 6000 and adjusts all addresses accordingly.
Advantage: Programs can run in different memory locations without recompilation.
3. Dynamic Loading
Only the necessary parts of a program are loaded into memory.
Other parts are loaded on demand when needed.
Reduces memory usage and improves performance.
Example:
- A large program like Microsoft Word loads only the basic editor at startup.
- Additional features (e.g., spell check, PDF export) load only when required.
Advantage: Saves memory and load time, especially for large applications.
4. Dynamic Linking Loader
Instead of loading the entire program, the loader loads and links shared libraries (DLLs) at runtime.
Improves memory efficiency by sharing common library files among multiple programs.
Example:
- Multiple applications use MSVCRT.dll (C Runtime Library) instead of loading a separate copy for each program.
Advantage: Reduces program size and saves memory by using shared libraries.
Steps of the Loading Process
- Program Selection – The OS selects the program to be loaded.
- Memory Allocation – The OS finds a suitable memory location.
- Loading Program Code – The program’s binary instructions are copied from disk to RAM.
- Address Binding – Logical addresses are mapped to physical addresses (if needed).
- Execution Start – The program starts running when control is transferred to its main() function.
Comparison of Different Loaders
Loader Type | When It Loads? | Flexibility | Example Use Case |
---|---|---|---|
Absolute Loader | Before execution | Simple embedded systems | |
Relocatable Loader | Before execution | Multiprogramming OS | |
Dynamic Loading | During execution | Large applications, OS kernels | |
Dynamic Linking | During execution | Shared libraries (DLLs, SO files) |
Conclusion
Loading is a crucial function of the operating system that ensures programs are properly placed in memory and ready for execution. Dynamic loading and linking improve memory efficiency and system performance, making them widely used in modern operating systems.