Answered step by step
Verified Expert Solution
Link Copied!

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 =512;
long long AccessTime =1;
int CurrPgeNum =0;
map psizes;
struct page {
long pageNum;
long validBit;
long long lastAccess;
};
int lookupMemoryLoc(int pid, int loc, int pagesize){
// This function is meant to find the number of the current page inside the pages
if (loc <0|| loc > psizes[pid]){// first check to see if the memory location is valid for this process
throw std::invalid_argument("Error: Recieved out-of-bounds memory location for specified process");
}
int result =(int)ceil((float)((float)loc/(float)pagesize))-1;
return result;
}
int main(int argc, char** argv){
if (argc !=6){
printf("Invalid number of command line arguments
");
return(-1);
}
long pageSize = atoi(argv[3]);
long Case =-1;
string algo = argv[4];
if (algo.compare("FIFO")==0){
Case =0;
} else if (algo.compare("LRU")==0){
Case =1;
} else if (algo.compare("Clock")==0){
Case =2;
}else{
printf("Invalid parameter value for page replacement algorithm
");
exit(-1);
}
string flag = argv[5]; //This to look for the pre pagings
bool prePaging;
bool notPrepage = true;
if (flag =="+")
prePaging = true;
else if (flag =="-")
prePaging = false;
else{
printf("Invalid value for the argument of pre-paging [+/-]
");
exit(-1);
}
vector table; //table for all programs in plist
//Starting the file
ifstream plist (argv[1], ifstream::in);
int plistLines =0; //each real plist line is a program, so this is our program counter
char c;
char lastChar ='
';
bool readPID = false;
string currPID ="";
int pid =0;
string currSize ="";
int size =0;
int numPages;
while(plist.good()){
c = plist.get();
if (c =='
' && lastChar !='
'){
size = atoi(currSize.c_str());
pid = atoi(currPID.c_str());
// save the number of memory locations for each process in a map
psizes[pid]= size;
numPages =(int)(ceil(((float)size/(float)pageSize)));
page** anythingreally = new page*[numPages];
for(int i =0; ipageNum = CurrPgeNum;
CurrPgeNum++;
anythingreally[i]->validBit =0;
anythingreally[i]->lastAccess =0;
}
table.push_back(anythingreally);
//delete[] anythingreally;
plistLines++; // increment programs counter
//printf("PID 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 = NumAddresses/pageSize;
int pagesPerProgram = numPages/plistLines;
page* mainMemory[numPages]; //table for our main program
for (int i =0; i < plistLines; ++i)
for (int j =0; j < pagesPerProgram; ++j){//starting the paging
mainMemory[j+pagesPerProgram*i]= new page;
mainMemory[j+pagesPerProgram*i]= table[i][j];
table[i][j]->validBit =1; //set page as in memory
table[i][j]->lastAccess = AccessTime; //update time accessed
AccessTime++;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

Know how to create a position description

Answered: 1 week ago