# Program to simulate Free Space Management

Share
1. Using Bitmap

A sequence or collection of bits, where each bit stands for a disk block, is known as a bitmap or bit vector. The bit has two possible values: 0 and 1: 0 means the block is allocated, and 1 means the block is free.

``````#include<stdio.h>
#include<stdlib.h>
int main(){
int status;

printf("Enter start address : ");
printf("Enter the length:");
scanf("%d",&length);

//constructing bitmaps, assuming memory address exactly divisible by 3 and 4 is already allocated
for(int i=0;i<length;i++){
status[i] = 0;
}else{
status[i] = 1;
}
}

printf("Bitmap [ Assuming memory address exactly divisible by 3 and 4 is already allocated] \n");
//printing bitmap
for(int i=0;i<length;i++){
printf("%d",status[i]);
}
printf("\n");
return 0;
}
``````

OUTPUT 2. Using Linked List

Link List It is an alternative strategy for managing open space. In this method, all the free blocks are linked together, and the first free block’s pointer is kept in the cache. As a result, a pointer will link each of the disks’ free blocks together.

``````#include<stdio.h>
#include<stdlib.h>

struct freeSpace{
struct freeSpace* next;
};

struct freeSpace* temp;
temp = (struct freeSpace*)malloc(sizeof(struct freeSpace*));
temp->next = NULL;
}else{
struct freeSpace *lastNode = head;
while(lastNode->next != NULL)
{
lastNode = lastNode->next;
}
lastNode->next = temp;
}
}
int main(){
struct freeSpace *head = NULL;
struct freeSpace *temp = head;
printf("Enter start address : ");
printf("Enter the length:");
scanf("%d",&length);
//constructing linked list, assuming memory address exactly divisible by 2 and 5 is free
for(int i=0;i<length;i++){
}
}

printf("Linked List [Assuming memory address exactly divisible by 2 and 5 is free] \n");
//printing bitmap
while (temp->next!=NULL){
temp=temp->next;
}
printf("NULL \n");
return 0;
}
``````

OUTPUT Source code repository: https://github.com/CodewithSudeep/operating-system-c-program

Other C Programs: https://codewithsudeep.com/category/c-program/

Share Healing