Wednesday, May 22nd

Last update12:59:40 PM GMT

Dynamic Linking

Write e-mail

The concept of Dynamic Linking is an extension of Dynamic Loading. We saw in Dynamic Loading, that the routine is not loaded into memory till it is called. In this also, something similar is done, but differently and of course with some improvements. 


In case of Dynamic Loading we saw separate copies of the routine are required to be included in the executable code of each program using that routine (wasting a lot of memory space). But in case of Dynamic Linking, in place of the routine a stub is included in each of the executable image where that routine is referenced. This stub is a very small piece of code which when executed, does two things:

  1. When a library routine is called, this stub checks if that routine is in memory or not. If not, it loads the routine into memory.
  2. After the routine is in memory, the stub replaces itself with the address of the routine and then executes it. Thus, next time the routine is called; it is executed directly without incurring any linking overhead.

So the benefit of this is that only one copy of the library routine is required to be kept in memory for all the processes that use it. 

Dynamic Linking is widely exploited these days to incorporate new bug fixes. A library may be replaced by a new one (after bug(s) have been corrected in it). After this all the executables using that routine will automatically start using the new version. 

If dynamic linking was not there, each of the executable would have required to be re-linked again to the new library version.

Dynamic Linking, unlike dynamic loading, requires help from OS. When two processes are accessing a library routine at the same time, it is only OS that can protect them from accessing the same memory address simultaneously.

Most of the operating systems today have provisions for dynamic linking. Dynamic-link library or DLL, is Microsoft's implementation of the shared library concept in the Microsoft Windows and OS/2 operating systems. These libraries usually have the file extension DLLOCX.

Share this post

Add comment

Please refrain from using slang or abusive language in the comments.
To avoid waiting for your comment to be published after being reviewed, please log in as a registered user.

Security code

Web Hosting