first fit algorithm
C++
// Function to allocate memory to
// blocks as per First fit algorithm
void firstFit(int blockSize[], int m,
int processSize[], int n)
{
// Stores block id of the
// block allocated to a process
int allocation[n];
// Initially no block is assigned to any process
memset(allocation, -1, sizeof(allocation));
// pick each process and find suitable blocks
// according to its size ad assign to it
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (blockSize[j] >= processSize[i])
{
// allocate block j to p[i] process
allocation[i] = j;
// Reduce available memory in this block.
blockSize[j] -= processSize[i];
break;
}
}
}
cout << "\nProcess No.\tProcess Size\tBlock no.\n";
for (int i = 0; i < n; i++)
{
cout << " " << i+1 << "\t\t"
<< processSize[i] << "\t\t";
if (allocation[i] != -1)
cout << allocation[i] + 1;
else
cout << "Not Allocated";
cout << endl;
}
}
Also in C++:
- Title
- building native binary with il2cpp unity
- Category
- C++
- Title
- double ended queue in c++ stl
- Category
- C++
- Title
- c++ loop trhought object
- Category
- C++
- Title
- screen record ios simulator
- Category
- C++
- Title
- change int to string cpp
- Category
- C++
- Title
- how to hide ui elements unity
- Category
- C++
- Title
- decimal to hex cpp
- Category
- C++
- Title
- c++ do you not inherit constructor
- Category
- C++
- Title
- vector last c++
- Category
- C++
- Title
- std::substring
- Category
- C++
- Title
- char to string c++
- Category
- C++
- Title
- mingw32/bin/ld.exe: C:\Users\mfrom\AppData\Local\Temp\ccSKcRks.o:PizzaPi.cpp:(.text$_ZN5PizzaC2Ev[__ZN5PizzaC2Ev]+0xa): undefined reference to `vtable for Pizza' collect2.exe: error: ld returned 1 exit status
- Category
- C++
- Title
- pairs in c++
- Category
- C++
- Title
- msdn parse command line
- Category
- C++
- Title
- initialization list c++
- Category
- C++
- Title
- how to iterate through a map in c++
- Category
- C++
- Title
- how to get os name in c++
- Category
- C++
- Title
- set in c++
- Category
- C++
- Title
- error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(s[i] != "b"){
- Category
- C++
- Title
- double to int c++
- Category
- C++
- Title
- insert at position in vector c++
- Category
- C++
- Title
- nearest integer rounding in c++
- Category
- C++
- Title
- make an x using asterisk c++
- Category
- C++
- Title
- using namespace std in c++
- Category
- C++
- Title
- level order traversal
- Category
- C++
- Title
- min coin change problem dp
- Category
- C++
- Title
- ue4 modular character
- Category
- C++
- Title
- git branch in my bash prompt
- Category
- C++
- Title
- translate
- Category
- C++
- Title
- 1d fixed length arrays c++
- Category
- C++
- Title
- qt make widget ignore mouse events
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- how to append an element to an array in cpp
- Category
- C++
- Title
- How to read a file in in C++
- Category
- C++
- Title
- c++ convert int to double
- Category
- C++
- Title
- c++ remove text file
- Category
- C++
- Title
- c++ delete dynamically allocated array
- Category
- C++
- Title
- max heap c++ stl;
- Category
- C++
- Title
- c++ string to stream
- Category
- C++
- Title
- matrix eigen c++ example
- Category
- C++
- Title
- advanced c++ topics
- Category
- C++
- Title
- stl sort in c++
- Category
- C++
- Title
- apple and orange hackerrank solution in c++
- Category
- C++
- Title
- what is order in of preeendence in float, int, char, bool
- Category
- C++
- Title
- declaring vector c++
- Category
- C++
- Title
- rick astley - never gonna give you up
- Category
- C++
- Title
- preorder traversal
- Category
- C++
- Title
- Arrays hackerrank solution in c++
- Category
- C++
- Title
- what is sigsegv error in c++
- Category
- C++
- Title
- cube mapping sdl
- Category
- C++
- Title
- traverse map c++
- Category
- C++
- Title
- map.erase in c++
- Category
- C++
- Title
- pass vector by reference c++
- Category
- C++
- Title
- how to convert string into number
- Category
- C++
- Title
- array sort c++
- Category
- C++
- Title
- font awesome bootstrap cdn
- Category
- C++
- Title
- kruskal c++
- Category
- C++
- Title
- container class in c++
- Category
- C++
- Title
- declaring 2d vector in c++
- Category
- C++
- Title
- making random numbers in c++
- Category
- C++
- Title
- c++ comment
- Category
- C++
- Title
- formal parameter c++
- Category
- C++
- Title
- std::reverse
- Category
- C++
- Title
- c++ class constructor
- Category
- C++
- Title
- c++ get length of array
- Category
- C++
- Title
- linear search in c++
- Category
- C++
- Title
- char* to int in cpp
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- console colors in C++
- Category
- C++
- Title
- how to iterate over unordered_map c++
- Category
- C++
- Title
- how to get a letter from the users string in c++
- Category
- C++
- Title
- array 2d to 1d
- Category
- C++
- Title
- c++ program how to let the user choose different game modes
- Category
- C++
- Title
- string length c++
- Category
- C++
- Title
- c++ sort array of ints
- Category
- C++
- Title
- create a bitset of 1024 bits,
- Category
- C++
- Title
- delete 2d dynamic array c++
- Category
- C++
- Title
- char **
- Category
- C++
- Title
- c++ set add element
- Category
- C++
- Title
- rand c++
- Category
- C++
- Title
- recursion in cpp with reference
- Category
- C++
- Title
- c++ vector add element
- Category
- C++
- Title
- queue c++
- Category
- C++
- Title
- Html tabulation
- Category
- C++
- Title
- GetCurrentThreadId c
- Category
- C++
- Title
- is not a nonstatic data member or base class of class
- Category
- C++
- Title
- c++ class method example
- Category
- C++
- Title
- how to check sqrt of number is integer c++
- Category
- C++
- Title
- c++ string to integer without stoi
- Category
- C++
- Title
- hashset in c++
- Category
- C++
- Title
- getch c++ library
- Category
- C++
- Title
- Check if a Number is Odd or Even using Bitwise Operators
- Category
- C++
- Title
- C++ If
- Category
- C++
- Title
- cut by delimiter c++
- Category
- C++
- Title
- how to return a vector c++
- Category
- C++
- Title
- how to get size of 2d vector in c++
- Category
- C++
- Title
- c++ method name
- Category
- C++
- Title
- what is difference between ciel and floor
- Category
- C++
- Title
- how are graphics in games made
- Category
- C++
- Title
- c++ loop through int array
- Category
- C++