pmj642 / Free-Memory-Allocation-Algorithms

A C++ program to calculate time complexity of First, Best and Worst Fit algorithms

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A C++ program to calculate and study time complexity of First, Best and Worst Fit algorithms

Libraries Included

  1. iostream(standard i/o)
  2. ctime (timer)
  3. cstring (strcpy() function)
  4. iomanip (formatted output)

Functions Used

  • int main(void);

    driver function

  • void call_algo(int freeblocks[], int n_blocks, int process[], int n_process);

    Function to call three memory allocation functions

  • int firstFit(int blockSize[], int m, int processSize[], int n);

    Function to allocate memory to processes as per First fit algorithm

  • int bestFit(int blockSize[], int m, int processSize[], int n);

    Function to allocate memory to processes as per Best fit algorithm

  • int worstFit(int blockSize[], int m, int processSize[], int n);

    Function to allocate memory to processes as per Worst fit algorithm

Later all three functions return number of unallocated processes

The main() function

The main function is the driver function, it performs the following functions:

  1. taking no_of_processes followed by, the free space requirements of the processes from the process file
  2. taking input files one at a time (input0.txt, input1.txt, input2.txt, input3.txt, input4.txt) and analysing them using all three algorithms (First, Best & Worst fit)
  3. it calls the algorithms through the 'call_algo' function
  4. the output is formatted by using I/O manipulation functions (setw)

Output

The output generated by the program can be found at https://github.com/pmj642/time-complexity-of-free-memory-allocation-algorithms/blob/master/output.txt

alt text

Note:

All files are accessed using the function 'freopen' which redirects the file data to the 'stdin' console (creates a portal between the user input file and the file opened by freopen) and enables reading of file data from the 'stdin' console as we usually do. This portal is closed after use by using 'fclose' function.

About

A C++ program to calculate time complexity of First, Best and Worst Fit algorithms

License:GNU General Public License v3.0


Languages

Language:C++ 100.0%