Friday, Oct 20th

Last update12:59:40 PM GMT

Dynamic Loading

Write e-mail

In this article we will explore in detail the concepts of Dynamic Loading in an operating system. We all know the size of physical memory is limited and to execute a process, it is necessary to have it and its data in physical memory.

argaiv1874

In order to have better utilization of memory space, dynamic loading is employed. 

Dynamic Loading means a routine is not loaded in the memory until it is called. That is, it is kept at some disk and brought into memory space when it is called by the main program (or another routine). But how does it happen? How does the routine gets its addresses mapped to the physical memory?

The routine is kept on disk in a relocatable address format. At the time when a routine calls another routine, it first checks whether the called routine is already in memory or not. If its not there, the address tables of the routine (currently on disk) are updated with the correct physical addresses (using the relocatable address fomat) and brought into physical memory. This mapping is done by relocatable linking loader. Now the control is passed to the newly loaded routine for execution.

If we talk with respect to C/C++, not all systems support dynamic loading. UNIX-like operating systems such as Mac OS X, Linux, and Solaris provide dynamic loading with the C programming language "dl" library. The Windows operating system provides dynamic loading through the Windows API. 

Advantages:

  1. The main advantage of Dynamic Loading is that unused routine is never loaded into the memory and that makes good amount of savings for the code that handle less frequently occurring cases such as error routines, since these part of code are never loaded into memory as long as error condition doesn’t come.
  2. It does not require help from the OS as the complete responsibility of designing programs involving Dynamic Loading lies with the coder. OS may provide some library routines to handle dynamic loading. 

Disadvantage:

  1. The responsibility of unloading the routine is also required to be handled by the programmer. Ignoring this may lead to a possible memory leak.
  2. With Dynamic Loading we still require routines refernced by another routine in the overall executable image. That is to say, even if a routine is not loaded, the reference to the called routine still exists in the calling routine which causes two drawbacks:
  • Separate copy of referenced routine is needed in each program using that routine, wasting both disk space and main memory.
  • The overall executable code produced is difficult to read and understand.

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
Refresh

Web Hosting