链接和加载是在程序执行中发挥重要作用的实用程序。链接吸收汇编器生成的目标代码并将它们组合起来生成可执行模块。另一方面,加载将这个可执行模块加载到主内存中执行。
加载:
将程序从辅助内存带到主内存称为加载。
链接:
在程序的所有模块或所有功能之间建立链接以继续执行程序称为链接。
链接和加载之间的差异:
- 链接和加载之间的主要区别在于链接生成程序的可执行文件,而加载将通过链接获得的可执行文件加载到主存中执行。
- 链接引入由汇编程序生成的程序的目标模块。但是,加载会引入链接生成的可执行模块。
- 链接结合了程序的所有目标模块以生成可执行模块,还将目标模块中的库函数链接到高级编程语言的内置库。另一方面,加载会为主内存中的可执行模块分配空间。
加载和链接进一步分为两种类型:
Static | Dynamic |
---|---|
Loading the entire program into the main memory before start of the program execution is called as static loading. | Loading the program into the main memory on demand is called as dynamic loading. |
Inefficient utilization of memory because whether it is required or not required entire program is brought into the main memory. | Efficient utilization of memory. |
Program execution will be faster. | Program execution will be slower. |
Statically linked program takes constant load time every time it is loaded into the memory for execution. | Dynamic linking is performed at run time by the operating system. |
If the static loading is used then accordingly static linking is applied. | If the dynamic loading is used then accordingly dynamic linking is applied. |
Static linking is performed by programs called linkers as the last step in compiling a program. Linkers are also called link editors. | In dynamic linking this is not the case and individual shared modules can be updated and recompiled.This is one of the greatest advantages dynamic linking offers. |
In static linking if any of the external programs has changed then they have to be recompiled and re-linked again else the changes won’t reflect in existing executable file. | In dynamic linking load time might be reduced if the shared library code is already present in memory. |