5
$\begingroup$

First of all, I saw many answers of this topic in Quora, Stackoverflow, and this site. But, I couldn't definitely understand the difference between dynamic loading and dynamic linking.

What I understood until now is this.

Dynamic loading : system library or other routine is loaded during run-time and it is not supported by OS.

Dynamic linking : system library or other routine is linked during run-time and it is supported by OS.

What I'm confusing is the behaviour of this two concepts. I know that loading occurs after linking like below image. (from Operating System concepts 9th edition, Chapter 8 figure 8.3)

enter image description here

Then, my question is that does dynamic loading is occured after dynamic linking? If I'm wrong, what is the exact difference between two concepts?

$\endgroup$
  • $\begingroup$ This is a total cross posting question,this same question was asked 3yrs+ in stackoverflow.So this is a total duplication of this stackoverflow.com/q/10052464/6321488 $\endgroup$ – quintumnia Jun 2 '18 at 17:14
  • 1
    $\begingroup$ " I saw many answers of this topic in Quora, Stackoverflow, and this site. But, I couldn't definitely understand the difference between dynamic loading and dynamic linking." -- What, specifically, didn't you understand? $\endgroup$ – Raphael Jun 3 '18 at 11:27
  • $\begingroup$ I think this question may be offtopic. Community votes, please! $\endgroup$ – Raphael Jun 3 '18 at 11:28
  • 1
    $\begingroup$ @Raphael It's a conceptual question about models of programming. That's computer science. $\endgroup$ – Gilles 'SO- stop being evil' Jun 5 '18 at 22:33
2
$\begingroup$

Let me explain these terms in the simplest way possible. Now since both the terms have the word dynamic in them, both occur during execution.

Dynamic Loading : Suppose our program that is to be executed consist of various modules. Of course its not wise to load all the modules into main memory together at once(in some cases it might not be even possible because of limited main memory). So basically what we do here is we load the main module first and then during execution we load some other module only when its required and the execution cannot proceed further without loading it.

Dynamic Linking : Suppose our program has some functions whose definition is present in some system library. We do know the header file only consists of declarations of functions and not definitions. So during execution when the function gets called we load that system library into main memory and link the function call inside our program with the function definition inside system library.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ Then, in dynamic loading, when linking process occurs? For my knowledge, loading occurs after linking, that's my point. $\endgroup$ – molamola Jun 2 '18 at 12:15
  • $\begingroup$ Yes loading occurs after linking but its not to be confused with dynamic loading. $\endgroup$ – Sumeet Jun 2 '18 at 14:53
  • $\begingroup$ The Diagram shown has nothing to do with dynamic loading. It simply shows the steps that takes place before any execution begins. $\endgroup$ – Sumeet Jun 2 '18 at 14:53
  • $\begingroup$ "Let me explain these terms in the simplest way possible. " -- Why do you think that's helpful? Presumably, other "simple" explanations already failed to help the OP, as they indicate in their question. $\endgroup$ – Raphael Jun 3 '18 at 11:27
  • $\begingroup$ This answer helped me till certain level, but now i m confused with 2 more things now: 1. "loading occurs after linking" - for linking to happen, isn't is has to be loaded first? 2. When you mentioned function in dynamic linking, does it mean that module containing that function is already loaded into Main memory and then linking happens? Please help. $\endgroup$ – Vipul Goyal Apr 9 at 10:14
1
$\begingroup$

Dynamic Loading https://www.youtube.com/watch?v=qfGql6sGlZg
Dynamic Linking https://www.youtube.com/watch?v=RKmAJMe3t9E

Assume the code of a program is consists of several source codes and All of these source codes are compiled. As a result of these compilations, there exist several modules per source codes. Then, Assume a linker is called to link those modules into an executable module. In dynamic loading, after the linker is called, only main module is loaded into memory. During execution, if main module needs another module which is already linked in executable module, then calling module calls relocatable linking loader to load the called module into apporiate location in the processes logical adress space.

In Dynamic Linking, When a module needs to be called, that module is loaded into memory and a link between the calling module and called module is established by the stub which is a piece of code that is linked in linking time of the program. Dynamic Linking mostly used with shared libraries which different users may use.

| cite | improve this answer | |
$\endgroup$
0
$\begingroup$

Dynamic loading is the process of loading the dependent library or routine on-demand or at some time at run-time after load-time (the time at which the main program executable is loaded). This is contrast to loading all dependencies at load-time together with the main program. The Windows loader for example supports both techniques. The loading process completes when the library has been successfully loaded into main memory.

When the program attempts to call an imported function for the first time, that library that contains that function may or may not have been loaded yet. Initially, the compiler places a temporary small function, called a stub, that gets called instead of the imported function. The stub calls into the OS. If the library is currently not loaded, it gets loaded (this step is called dynamic loading). Then, the stub is modified so that it calls the imported function directly the next time it gets called. This process is called dynamic linking. The component of the OS that performs both steps is called the dynamic linker or the dynamic linking loader.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.