Why do we need a dynamic library for? How is it different from a static library

Questions by sivagangadhar1983

Showing Answers 1 - 9 of 9 Answers

Zahid K

  • Nov 12th, 2007
 



 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.

  Was this answer useful?  Yes

vthegde

  • Dec 15th, 2007
 

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

  Was this answer useful?  Yes

sk_seeker

  • Dec 29th, 2007
 

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.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions