8. 1 Background ●●● ●●●● ●●●●● ●●●● ●●0●● ●●●● ●●●● relocation reqister 14000 logical address address CPU memory 346 14346 MMU
17 8.1 Background
8. 1 Background ●●● ●●●● ●●●●● ●●●● ● Dynamic Loading ●●0●● ●●●0 ●●●● Should the entire program and data of a process be in physical memory for the process to execute? o Routine is not loaded until it is called o Better memory-space utilization; unused routine is never loaded e Useful when large amounts of code are needed to handle infrequently occurring cases, such as error routines No special support is required from the operating system o os provides library routines to help programmer to implement the dynamic loading
18 8.1 Background ⚫ Dynamic Loading ⚫ Should the entire program and data of a process be in physical memory for the process to execute? ⚫ Routine is not loaded until it is called ⚫ Better memory-space utilization; unused routine is never loaded ⚫ Useful when large amounts of code are needed to handle infrequently occurring cases,such as error routines ⚫ No special support is required from the operating system ⚫ OS provides library routines to help programmer to implement the dynamic loading
8. 1 Background ●●● ●●●● ●●●●● ●●●● ●●0●● Dynamic linking and shared libraries ●●●● ●●●● ● Static linking System language libraries are treated like any other object module and are com bined by the loader into the binary program Image Each program on a system must include a copy of its language library (or at least the routines referenced by the program) in the executable image Waste both disk space and main memory
19 8.1 Background ⚫ Dynamic linking and shared libraries ⚫ Static linking ⚫ System language libraries are treated like any other object module ▪ and are combined by the loader into the binary program image ⚫ Each program on a system must include a copy of its language library (or at least the routines referenced by the program) in the executable image ▪ Waste both disk space and main memory
8. 1 Background ●●● ●●●● ●●●●● ●●●● ●●0●● ● DynamIc linking ●●●0 ●●●● Linking is postponed until execution time e Stub Is small piece of code and is included in the im age for each library routine reference It used to locate the appropriate memory-resident library routine Or used to load the library if the routine is not already present
20 8.1 Background ⚫ Dynamic linking ⚫ Linking is postponed until execution time ⚫ Stub ▪ Is small piece of code and is included in the image for each library routine reference ▪ It used to ▪ locate the appropriate memory-resident library routine ▪ Or used to load the library if the routine is not already present
8. 1 Background ●●● ●●●● ●●●●● ●●●● When the stub is executed ●●0●● ●●●0 Operating system needed to check if routine is in . o processes'memory address it replaces itself with the address of the routine, and executes the routine The next time, the library routine is executed directly, incurring no cost for dynamic linking
21 8.1 Background ▪ When the stub is executed, ▪ Operating system needed to check if routine is in processes’ memory address ▪ it replaces itself with the address of the routine, and executes the routine ▪ The next time, the library routine is executed directly, incurring no cost for dynamic linking