Memory Management
Memory Management
ANS: Memory is the important part of the computer that is used to store the data. Its
management is critical to the computer system because the amount of main memory
available in a computer system is very limited. At any time, many processes are competing
for it. Moreover, to increase performance, several processes are executed simultaneously.
For this, we must keep several processes in the main memory, so it is even more important
to manage them effectively.
o Memory manager is used to keep track of the status of memory locations, whether it is
free or allocated. It addresses primary memory by providing abstractions so that software
perceives a large memory is allocated to it.
o Memory manager permits computers with a small amount of main memory to execute
programs larger than the size or amount of available memory. It does this by moving
information back and forth between primary memory and secondary memory by using the
concept of swapping.
o The memory manager is responsible for protecting the memory allocated to each process
from being corrupted by another process. If this is not ensured, then the system may
exhibit unpredictable behavior.
o Memory managers should enable sharing of memory space between processes. Thus, two
programs can reside at the same memory location although at different times.
Linking and Loading are utility programs that play an important role in the
execution of a program. Linking intakes the object codes generated by the
assembler and combines them to generate the executable module. On the other
hand, the loading loads this executable module to the main memory for
execution.
ANS: To bring the program from secondary memory to main memory is called
Loading. It is performed by a loader. It is a special program that takes the input
of executable files from the linker, loads it to the main memory, and prepares this
code for execution by a computer.
There are two types of loading in the operating system:
• Static Loading:
• Loading the entire program into the main memory before the start of
the program execution is called static loading.
• If static loading is used then accordingly static linking is applied.
• Dynamic Loading:
• Loading the program into the main memory on demand is called
dynamic loading.
• If dynamic loading is used then accordingly dynamic linking is
applied.
QUS:What is Linking?
ANS: Establishing the linking between all the modules or all the functions of the
program in order to continue the program execution is called linking. Linking is a
process of collecting and maintaining pieces of code and data into a single file.
Linker also links a particular module into the system library. It takes object
modules from the assembler as input and forms an executable file as output for
the loader. Linking is performed at both compile time when the source code is
translated into machine code, and load time, when the program is loaded into
memory by the loader. Linking is performed at the last step in compiling a
program.
• Static Linking:
• A statically linked program takes constant load time every time it is
loaded into the memory for execution.
• Static linking is performed by programs called linkers as the last step
in compiling a program. Linkers are also called link editors.
• 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 the existing executable file.
• Dynamic Linking:
• Dynamic linking is performed at run time by the operating system.
• 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 dynamic linking load time might be reduced if the shared library
code is already present in memory.