Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Make a GUI code for a virtual meomery simulator using C + + #include #include #include #include #include #include #include using namespace std; #include int
Make a GUI code for a virtual meomery simulator using C
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#include
int NumAddresses ;
long long AccessTime ;
int CurrPgeNum ;
map psizes;
struct page
long pageNum;
long validBit;
long long lastAccess;
;
int lookupMemoryLocint pid, int loc, int pagesize
This function is meant to find the number of the current page inside the pages
if loc loc psizespid first check to see if the memory location is valid for this process
throw std::invalidargumentError: Recieved outofbounds memory location for specified process";
int result intceilfloatfloatlocfloatpagesize;
return result;
int mainint argc, char argv
if argc
printfInvalid number of command line arguments
;
return;
long pageSize atoiargv;
long Case ;
string algo argv;
if algocompareFIFO
Case ;
else if algocompareLRU
Case ;
else if algocompareClock
Case ;
else
printfInvalid parameter value for page replacement algorithm
;
exit;
string flag argv; This to look for the pre pagings
bool prePaging;
bool notPrepage true;
if flag
prePaging true;
else if flag
prePaging false;
else
printfInvalid value for the argument of prepaging
;
exit;
vector table; table for all programs in plist
Starting the file
ifstream plist argv ifstream::in;
int plistLines ; each real plist line is a program, so this is our program counter
char c;
char lastChar
;
bool readPID false;
string currPID ;
int pid ;
string currSize ;
int size ;
int numPages;
whileplistgood
c plist.get;
if c
&& lastChar
size atoicurrSizecstr;
pid atoicurrPIDcstr;
save the number of memory locations for each process in a map
psizespid size;
numPages intceilfloatsizefloatpageSize;
page anythingreally new pagenumPages;
forint i ; ipageNum CurrPgeNum;
CurrPgeNum;
anythingreallyivalidBit ;
anythingreallyilastAccess ;
table.pushbackanythingreally;
delete anythingreally;
plistLines; increment programs counter
printfPID Number: d Memory Size: d
pid, size;
currSize ; reset vars for next line
currPID ;
readPID false;
else if readPID && c read all until spaces
currPID currPID c;
else if c
readPID true; reading the size
else accessing rest of locations in memory
currSize currSize c;
lastChar c;
plist.close;
applying in the main program
numPages NumAddressespageSize;
int pagesPerProgram numPagesplistLines;
page mainMemorynumPages; table for our main program
for int i ; i plistLines; i
for int j ; j pagesPerProgram; jstarting the paging
mainMemoryjpagesPerProgrami new page;
mainMemoryjpagesPerProgrami tableij;
tableijvalidBit ; set page as in memory
tableijlastAccess AccessTime; update time accessed
AccessTime;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started