Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (71 loc) · 1.95 KB
/
Copy pathmain.cpp
File metadata and controls
78 lines (71 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "./include/manager.h"
#include <iostream>
#include <vector>
// #include <istringstream>
#include <sstream>
#include <iterator>
using namespace std;
// Source - https://stackoverflow.com/a/2275160
// Posted by Jerry Coffin, modified by community. See post 'Timeline' for change history
// Retrieved 2026-04-12, License - CC BY-SA 3.0
std::vector<std::string> split(std::string const &input)
{
std::istringstream buffer(input);
std::vector<std::string> ret((std::istream_iterator<std::string>(buffer)),
std::istream_iterator<std::string>());
return ret;
}
int main()
{
cout << "Simulator" << endl;
Strategy strategy;
ll size;
cin >> size;
MemorySegment memory(size);
string s;
getline(cin >> ws, s);
while (s != "X")
{
vector<string> input = split(s);
if (s[0] == 'C')
{
memory.compaction();
}
else if (s[0] == 'S')
{
memory.statistics();
}
else if (s[0] == 'R' && s[1] == 'L')
{
ll num = 0;
for (ll i = 2; i < s.size(); i++)
{
if (s[i] != ' ')
{
num *= 10;
num += (s[i] - 48);
}
}
memory.request_release(num);
}
else if (s[0] == 'R' && s[1] == 'Q')
{
ll pid = std::stoull(input[1]);
ll amt = std::stoull(input[2]);
switch (input[3][0])
{
case 'B':
strategy = BEST_FIT;
break;
case 'W':
strategy = WORST_FIT;
break;
case 'F':
strategy = FIRST_FIT;
break;
}
memory.request_allocation(pid, amt, strategy);
}
getline(cin >> ws, s);
}
}