Git Product home page Git Product logo

free-memory-allocation-algorithms's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.