-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (55 loc) · 2.33 KB
/
main.cpp
File metadata and controls
63 lines (55 loc) · 2.33 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
/*
******************* Assignment #3: SIM ********************
******************* CS480, Summer 2024 ********************
Aeron Flores (826123084) and Jasmine Rasmussen (129935517)
***** Edoras #s: Aeron - CSSC4404; Jasmine - CSSC4427 *****
************************ main.cpp *************************
*/
#include <iostream>
#include "memory_management.h"
#include "stats.h"
#include "generate_request.h"
#include <iostream>
int main() {
const int numRequests = 10000;
int returnCode;
int success;
Request generator;
Stats ffStats;
Stats bfStats;
FirstFit firstFit;
BestFit bestFit;
// Pre-generated requests that contains the following:
// *** whether a process should be allocated or deallocated
// *** the number of units to allocate/deallocate
// *** the generated process ID
auto requests = generator.generateRequests(numRequests);
for(const auto& request : requests){
// If requested generated is allocation, allocate process to memory
if(request.isAlloc){
// Allocates a process using First Fit, then returns a code
// Return code is saved in stats for First Fit
returnCode = firstFit.allocateMem(request.processID, request.unitsRequested, ffStats);
ffStats.logRequest(returnCode);
ffStats.logFragments(firstFit.fragmentCount(), firstFit.sysMemory.size());
// Allocates a process using Best Fit, then returns a code
// Return code is saved in stats for Best Fit
returnCode = bestFit.allocateMem(request.processID, request.unitsRequested, bfStats);
bfStats.logRequest(returnCode);
bfStats.logFragments(bestFit.fragmentCount(), bestFit.sysMemory.size());
}
// else, request generated was a deallocation
else {
// Deallocates a process for First Fit
success = firstFit.deallocateMem(request.processID);
ffStats.logRequest(success);
// Deallocates a process for Best Fit
success = bestFit.deallocateMem(request.processID);
bfStats.logRequest(success);
}
}
std::cout << "------------------- FIRST FIT ---------------------\n";
ffStats.printStats();
std::cout << "-------------------- BEST FIT ---------------------\n";
bfStats.printStats();
}