CSI 313: Operating System
Memory Management
Shifat Sharmin Shapla
Senior Lecturer
Memory Allocation
• Memory is a large array of bytes, where each byte
has its own address. The memory allocation can be
classified into two methods.
– contiguous memory allocation
– non-contiguous memory allocation.
Contiguous Memory allocation
• In this scheme, each file occupies a contiguous set of blocks on
the disk.
• For example, if a file requires n blocks and is given a block b as the
starting location, then the blocks assigned to the file will be: b,
b+1, b+2,……b+n-1. Example: array.
• That means the file will be allocated in continuous memory space.
• But if there is not enough continuous free memory space then the
file can not be allocated though there might be some non-
continuous free space in memory whose summation is equal or
larger than the required memory.
Contiguous Memory allocation
• Suppose, we have P1 = 10KB, and we have memory
of total 20 KB, where only 5KB is used and other
15KB is still unused but in non-contiguous way. So,
though there is free space in memory we can not
use it.
5KB 2KB 5KB 3KB 5KB
Contiguous Memory allocation
• Advantage:
– Access time will be faster as it is allocated in contiguous
way, so if we find the first address of the file we can easily
access the rest of the file. (Like array)
• Disadvantage:
– We can’t allocate process sometimes though we have free
space but in non-contiguous way.
– Leads to external fragmentation (Total memory space is
enough to satisfy a request or to reside a process in it, but
it is not contiguous, so it cannot be used).
Non-Contiguous Memory allocation
• The Non-contiguous memory allocation allows a
process to acquire the several memory blocks at the
different location in the memory according to its
requirement.
• This utilizes all the free memory space which is
created by a different process.
Non-Contiguous Memory allocation
• Suppose, we have P1 = 10KB, and we have memory
of total 20 KB, where only 5KB is used and other
15KB is still unused but scattered. So, we can use
the free spaces individually to store P1.
P1 P1
5KB 2KB 5KB 3KB 5KB
Non-Contiguous Memory allocation
• Advantage:
– reduces the wastage of memory which leads to internal
and external fragmentation
• Disadvantage:
– the available free memory space are scattered here and
there and all the free memory space is not at one place.
So this is time-consuming to search.
Contiguous Memory allocation
• As we know, file is loaded from secondary memory
to main memory(RAM) for better access.
• We can achieve contiguous memory allocation by
dividing memory into two ways.
– Fixed-sized partition.
– Variable-sized partition
Fixed Size Partitioning
• The system divides memory into fixed size partition.
• Size of each partition may or may not be same size.
Variable Size Partitioning
• The memory is treated as one unit and space allocated to a
process is exactly the same as required and the leftover space
can be reused again.