GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Operating System  >  Unix Programming
Go To First  |  Previous Question  |  Next Question 
 Unix Programming  |  Question 37 of 43    Print  
Why do we need a dynamic library for? How is it different from a static library

  
Total Answers and Comments: 3 Last Update: December 29, 2007     Asked by: sivagangadhar1983 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
November 12, 2007 18:26:29   #1  
Zahid K        

RE: Why do we need a dynamic library for? How is it di...


Static lib becomes the part of code which is linked with static library whereas when you link your code with dynamic library that always need the run time linking with that complied code(or execuatble).

We need dynamic library for some BSD licencing reason you can explore the details of open source licencing on net.

 
Is this answer useful? Yes | No
December 15, 2007 07:12:39   #2  
vthegde Member Since: December 2007   Contribution: 5    

RE: Why do we need a dynamic library for? How is it different from a static library
i think the other advantage is multiple processes can share the same image of the library. this would reduce the foorprint and memory requirements of the process during execution
 
Is this answer useful? Yes | No
December 29, 2007 04:21:47   #3  
sk_seeker Member Since: December 2007   Contribution: 51    

RE: Why do we need a dynamic library for? How is it different from a static library
My previous post just died on me. So let me repeat what I wrote before. If both reach the thread my apologies.

Linker: What does it do??
-------------------------
The job of the linker is to combine one or more object modules and/or one of more libraries into a load module (executable). A load module is a program which can be executed. The jobs that a linker does to produce a load module is listed below:
- Combine all the object modules into a single load module
- Relocate the object module as they are being combined.
- Link the object modules together as they are being combined
- Search libraries for external references/symbols not defined in the object modules.


Static Linking implies that all the object modules and libraries have to be copied to the load module. With more and more functionality load modules become large. Large load modules exhibit two main problems that have lead to many variations in linking designs.
- Large load modules take a lot of space on disk because a lot of data duplication occurs due to multiple copies of the same libraries in different load modules.
- Large load modules take a long time to load when the process actually starts running.

Some of the techniques used to solve the above two problems are:
- Load time dynamic linking to solve the unnecessary disk space usage problem
- Run time dynamic linking to solve the long load time problem

Load Time Dynamic Linking
-------------------------
Some libraries can be designated as load time dynamic link library. When the linker is linking from such a library it does not copy the library object modules into the load module. Instead it inserts information on where to find the library which of the library object modules to load and where to load them in the process address space. When the program is actually loaded the load time loader notices these load time dynamic link library references goes to these libraries and completes the library
loading process at that time. The advantage is that this method saves a lot of duplicate disk space usage as one library copy can be used by many processes.

Run Time Dynamic Linking
------------------------
The previous alternative postponed the step of loading the object files into the lod module from load module creation time to load module loading time. But if the objects to be loaded are many and big it will still take a lot more time to load the process completely (disk to memory transfer is highest time consuming) link and relocate all the object modules and start executing. I.e. the problem of large load time still exists. To solve this problem we have the concept of Run time Dynamic Linking. This concept postpones the linking step from load time to actual reference time during the run phase i.e. postpone linking until the actual time it is needed for further execution.

So instead of waiting for the entire (program code + library code) to be transfered from disk before the program starts running with run time dynamic linking we can start the program as soon as program code is transfered. So program starts much faster

There are other treadeoff with dynamic linking which I will not mention here.

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape