- iostream(standard i/o)
- ctime (timer)
- cstring (strcpy() function)
- iomanip (formatted output)
-
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 is the driver function, it performs the following functions:
- taking no_of_processes followed by, the free space requirements of the processes from the process file
- 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)
- it calls the algorithms through the 'call_algo' function
- the output is formatted by using I/O manipulation functions (setw)
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
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.