0% found this document useful (0 votes)
50 views8 pages

EX - NO.9 Implementation of Memory Management - Deallocation

The document describes an algorithm for implementing memory management and deallocation in C. It involves: 1) Creating free and allocated lists to track available and used memory blocks. 2) Upon process completion, finding the corresponding node in the allocated list and moving it to the free list. 3) Merging contiguous free blocks into single blocks to optimize free space. 4) Allocating new processes using first-fit, worst-fit, or best-fit allocation policies.

Uploaded by

ajithjoe
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views8 pages

EX - NO.9 Implementation of Memory Management - Deallocation

The document describes an algorithm for implementing memory management and deallocation in C. It involves: 1) Creating free and allocated lists to track available and used memory blocks. 2) Upon process completion, finding the corresponding node in the allocated list and moving it to the free list. 3) Merging contiguous free blocks into single blocks to optimize free space. 4) Allocating new processes using first-fit, worst-fit, or best-fit allocation policies.

Uploaded by

ajithjoe
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

for(i=0;i<nf;i++) { EX.NO.

9 IMPLEMENTATION OF MEMORY MANAGEMENT DEALLOCATION AIM


To write a C program to implement memory management scheme such that When a process finishes (taken as input) the appropriate node from the allocated list should be deleted and this free disk space should be added to the free space list. [Care should be taken to merge contiguous free blocks into one single block. This results in deleting more than one node from the free space list and changing the start and end address in the appropriate node]. For allocation use first fit, worst fit and best fit.

ALGORITHM Step - 1: Step - 2: Step - 3: Step - 4: Step 5: Step - 6: Step - 7: Step - 8: Step 9: Step 10: Step 11: outline void main() { int nf,i,npreq,nfinish,fin[5]; fstart=(struct freenode*)malloc(sizeof(struct freenode)); struct allocnode *a,*aptr; astart=(struct allocnode*)malloc(sizeof(struct allocnode)); pstart=(struct process*)malloc(sizeof(struct process)); struct freenode *ftemp; Get the no. of. available free holes & its size, start address, ending address and form a free list Get the no. of. Allocated process requests, its size, start and end address and process ID and form a allocated list Get the no. of. finished process quests, and its process ID Start from then first finished process request Compare its pid with pid of each node in the allocated list if any one alloc node matches, create a node for the free space and assign F->start =alloc->start; F->end=alloc->end Remove that alloc node in the allocated list call merge() to merge the free holes if possible Get the next finished process request and go to step 4 print the allocated list and free list End

printf("Enter the no.of.frames"); scanf("%d",&nf); printf("\nEnter size, start address ,end address "); ftemp=(struct freenode*)malloc(sizeof(struct freenode)); scanf("%d %d %d",&ftemp->size,&ftemp->start,&ftemp->end); ftemp->link=NULL; insertfreenode(ftemp,i); free(ftemp); displayfreenode(); } printf("Enter No.of.Process Request :"); scanf("%d",&npreq); struct process *ptemp; for(i=0;i<npreq;i++) { printf("Enter pid,size "); ptemp=(struct process *)malloc(sizeof(struct process)); scanf("%d %d",&ptemp->pid,&ptemp->size); ptemp->link=NULL; insertprocessnode(ptemp,i); free(ptemp); displayprocessnode(); } firstfit(); displayprocessnode(); displayfreenode(); displayallocnode(); a=astart; printf("Enter the No.of.finished process"); scanf("%d",&nfinish); for(i=0;i<nfinish;i++) { printf("\nEnter the finished process id"); scanf("%d",&fin[i]); while(a!=NULL) { if(a->pid==fin[i]) { if(a->link!=NULL) aptr->link=a->link; else aptr->link=NULL; //displayallocnode(); printf("Before dealloctn"); displayfreenode();

insertfree(a); printf("After dealloctn"); displayfreenode(); printf("After Merging"); merge(); displayfreenode(); break; } aptr=a; a=a->link; // } } displayfreenode(); printf("\n After allocation\n"); displayallocnode();

// } SAMPLE OUTPUT

Enter the no.of.free frames3 Enter size, start address ,end address 100 0 99 first 100 0 99 frame size start_addr End_addr ******************************************* 100 0 99 Enter size, start address ,end address 400 200 349 frame size start_addr End_addr ******************************************* 100 400 0 200 99 349

Enter size, start address ,end address 300 700 899 frame size start_addr End_addr ******************************************* 100 400 300 0 200 700 99 349 899

Enter No.of.allocated Process Request :2 Enter pid,start,end 1 350 399

Allocated list pid 1 start end ************************** 350 399 Enter pid,start,end 2 900 999 Allocated list pid 1 2 start end ************************** 350 399 900 999

frame size start_addr End_addr ******************************************* 100 400 300 Allocated list pid 1 2 start end ************************** 350 399 900 999 0 200 700 99 349 899

Before Deallocation

Enter the No.of.finished process2 Enter the finished process id 1 Before dealloctn frame size start_addr End_addr ******************************************* 100 400 300 0 200 700 99 349 899

After dealloctn frame size start_addr End_addr ******************************************* 100 400 50 300 After Merging frame size start_addr End_addr ******************************************* 100 450 300 Allocated list pid start end ************************** 2 900 999 Enter the finished process id2 frame size start_addr End_addr ******************************************* 100 450 300 0 200 700 99 399 899 0 200 700 99 399 899 0 200 350 700 99 349 399 899

After dealloctn frame size start_addr End_addr ******************************************* 100 0 99

450 300 100 After Merging

200 700 900

399 899 999

frame size start_addr End_addr ******************************************* 100 450 400 Allocated list pid start end ************************** EMpty list [canitha@192 ~]$ 0 200 700 99 399 999

After Deallocation

EX.NO.10

SIMULATION OF CONTIGUOUS FILE ALLOCATION

AIM To write a program to simulate contiguous file allocation in disk ALGORITHM Step 1: Get the no. of. blocks in a disk Step 2: Get the no. of. requests and the filename and no .of. blocks ie length for each filename Step 3: Initialize the status of all blocks as 0 to indicate it is free Step 4:For each file request, A. Initialize count to 0 B. Start from the first block to the last block C. If blk is free, increment count D. If count==length, space is available for the file request E. Make an entry in directory structure by writing filename, start blk no. and length Step 5: print the directory entry structure Step 6:print the free blocks which status value is 0 SAMPLE OUTPUT [canitha@192 ~]$ ./a.out Enter the no.of.blocks in a disk :5 Enter the No.of.Request3 Enter the filename :a1 2 Enter the length(No.of blocks) :found Enter the filename :a2 4 Enter the length(No.of blocks) : No space for the file :a2 Enter the filename :a3 1 Enter the length(No.of blocks) :found directory structure

************************ Filename Start Length ************************************* a1 0 2 a3 2 1 Free blocks ************** 3 4

You might also like