FOR FREE YEAR SOLVED

Advantages and Disadvantages Dynamic Linking

 

Advantages of Dynamic Linking

i) If a common shared library is already present in the main memory, then it is not required to load the same shared library file several times. It saves the main memory. 

 

ii) Modules that are not invoked during the execution of a program need not be linked to it at all.

 

For example, if some function like printf( ) is under a condition statement of your program, then it will load in the main memory when the condition is true and it is needed. If the condition is not true and it is not needed then it will not load in the main memory.  It saves the main memory. 

 

Example:

void main()

{

int a;

   scanf(“%d” ,&a);

   if( a == 24 )

    {

        Printf(“valid”);

    } 

   else

       a=a+1;

}

In the above code printf(“valid”) is optional to link.

 

iii) Dynamic linking also provides an interesting benefit when a library of common modules is updated—a program that invokes this module of the library automatically starts using the new version of this module. Dynamically linked libraries (DLLs) use some of these features to their advantage.

 

Disadvantage of Dynamic Linking 

The main disadvantage of dynamic linking is page fault because when the shared library module is not present in the main memory, the program loads the module into memory. This page fault occurs wastage of time and run time resolves of external references slow down the execution of the program.

 

So, at the time of conversion of a high-level language (assembly language) to object code, the assembler assigns the relocatable address to all symbols.

 

Now when the linker tries to complete all the linking and external resources again the addresses have been changed to new relocatable addresses for all symbols.