0% found this document useful (0 votes)
13 views5 pages

Program For Storage Allocatio1

The document describes three algorithms - first fit, best fit, and worst fit - for allocating processes of various sizes to blocks of memory. First fit allocates processes to the first block that fits, best fit allocates to the smallest fitting block, and worst fit allocates to the largest fitting block. The algorithms are implemented as functions that take block sizes, process sizes, and other parameters and return an allocation list and output.

Uploaded by

utsavarora1912
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Program For Storage Allocatio1

The document describes three algorithms - first fit, best fit, and worst fit - for allocating processes of various sizes to blocks of memory. First fit allocates processes to the first block that fits, best fit allocates to the smallest fitting block, and worst fit allocates to the largest fitting block. The algorithms are implemented as functions that take block sizes, process sizes, and other parameters and return an allocation list and output.

Uploaded by

utsavarora1912
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PROGRAM FOR STORAGE ALLOCATION

FIRST FIT

def firstFit(blockSize, m, processSize, n):

allocation = [-1] * n

for i in range(n):

for j in range(m):

if blockSize[j] >= processSize[i]:

allocation[i] = j

blockSize[j] -= processSize[i]

break

print(" Process No. Process Size Block no.")

for i in range(n):

print(" ", i + 1, " ", processSize[i],

" ", end = " ")

if allocation[i] != -1:

print(allocation[i] + 1)

else:

print("Not Allocated")

if __name__ == '__main__':

blockSize = [100, 500, 200, 300, 600]

processSize = [212, 417, 112, 426]


m = len(blockSize)

n = len(processSize)

firstFit(blockSize, m, processSize, n)

OUTPUT:

Process No. Process Size Block no.

1 212 2

2 417 5

3 112 2

4 426 Not Allocated

BEST FIT

def bestFit(blockSize, m, processSize, n):

allocation = [-1] * n

for i in range(n):

bestIdx = -1

for j in range(m):

if blockSize[j] >= processSize[i]:

if bestIdx == -1:

bestIdx = j

elif blockSize[bestIdx] > blockSize[j]:

bestIdx = j
if bestIdx != -1:

allocation[i] = bestIdx

blockSize[bestIdx] -= processSize[i]

print("Process No. Process Size Block no.")

for i in range(n):

print(i + 1, " ", processSize[i],

end = " ")

if allocation[i] != -1:

print(allocation[i] + 1)

else:

print("Not Allocated")

if __name__ == '__main__':

blockSize = [100, 500, 200, 300, 600]

processSize = [212, 417, 112, 426]

m = len(blockSize)

n = len(processSize)

bestFit(blockSize, m, processSize, n)
OUTPUT

Process No. Process Size Block no.

1 212 4

2 417 2

3 112 3

4 426 5

WORST FIT

def worstFit(blockSize, m, processSize, n):

allocation = [-1] * n

for i in range(n):

wstIdx = -1

for j in range(m):

if blockSize[j] >= processSize[i]:

if wstIdx == -1:

wstIdx = j

elif blockSize[wstIdx] < blockSize[j]:

wstIdx = j

if wstIdx != -1:

allocation[i] = wstIdx

blockSize[wstIdx] -= processSize[i]

print("Process No. Process Size Block no.")

for i in range(n):
print(i + 1, " ",

processSize[i], end = " ")

if allocation[i] != -1:

print(allocation[i] + 1)

else:

print("Not Allocated")

if __name__ == '__main__':

blockSize = [100, 500, 200, 300, 600]

processSize = [212, 417, 112, 426]

m = len(blockSize)

n = len(processSize)

worstFit(blockSize, m, processSize, n)

OUTPUT:

Process No. Process Size Block no.

1 212 5

2 417 2

3 112 5

4 426 Not Allocated

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy