Monday, 9 November 2020

What is Dynamic Loading and Dynamic Linking in OS?

 

Dynamic Loading and Dynamic Linking:

 

The word ‘loading’ means load the program or a module from secondary storage devices to main memory. Loading are of two types. One is the compile-time loading and second one is runtime loading. All the routines that are loaded in the main memory at the time of compilation is said to be static loading or compile time loading. The routines that are loaded in the main memory at the time of execution or running is said to be dynamic loading or runtime loading.

 

For ex: consider the following program:

 

 #include<stdio.h>

void main()

{

printf(“Welcome”);

}

 

Suppose the program occupies 1 KB in secondary storage. But it occupies hundreds of KBs in main memory because, some routines and header files should be loaded in main memory to execute that program. Generally, this loading is done at the time of execution. The meaning of dynamic loading in a single statement can be stated as – “with dynamic loading, a routine is not loaded until it is called”.

 

The main advantage of dynamic loading is that an unused routine is never loaded. So, we can obtain better memory space utilization. This scheme is particularly useful when large amounts of code are needed to handle frequently occurring cases.


Program execution stages

Fig: Execution stages of user program


The step by step execution of user program, linking the library files before the execution is said to be static linking. You can observe this linking in the above figure. Most operating systems support only static linking. We can say the definition of dynamic linking in a single statement as - “linking is postponed until execution time”.


No comments:

Post a Comment