hello all, what i have to do, is create x number of segment tables, with y numbe
ID: 3777551 • Letter: H
Question
hello all, what i have to do, is create x number of segment tables, with y number of segment entries, and each segment entry points to a page table which has z number of pages which has a trivial address, and a frame number that address is occupying. we are getting input file like:
process 0 :0x2F
process 1 :0x1A
so right now im working on creating these tables which point to eachother that i need to check everytime a process requests a certain address.. im trying to use pointers, but my TA said i could use vectors but i dont see how that would work. Can you help me out? see my code below this is where im at so far. i use visual studio
from the address i am getting the segment entry number, and the page entry number, can anyone help me out? this code wont compile and im not really good with pointers. can someone please tell me what i need to do / should do?
struct seg_Table {
seg_Table_Entry *pointerToSegmentEntry;
};
seg_Table *segTables;
struct seg_Table_Entry {
page_Table *pointerToPageTable;
};
seg_Table_Entry *segTableEntries;
struct page_Table_Entry {
string address;
int frameNumber;
};
page_Table_Entry *pageTableEntries;
struct page_Table {
page_Table_Entry *pointerToPageTableEntry;
};
page_Table *pageTables;
void create_tables(int x,int y, int z){/*x is numberOfProcesses,
y is segmentLength
z is segmentLength */
segTables = new seg_Table[x];
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) {
for (int k = 0; k < z; k++)
segTables[i].pointerToSegmentEntry[j].pointerToPageTable[j].pointerToPageTableEntry[z];
}
}
}
int main(int argc, char *argv[])
{
create_tables(3,4,4);
segTables[0].pointerToSegmentEntry[2].pointerToPageTable[2].pointerToPageTableEntry[3].address = "0x2F";
segTables[0].pointerToSegmentEntry[2].pointerToPageTable[2].pointerToPageTableEntry[3].frameNumber = 0;
cout << segTables[0].pointerToSegmentEntry[2].pointerToPageTable[2].pointerToPageTableEntry[3].address << endl;
cout << segTables[0].pointerToSegmentEntry[2].pointerToPageTable[2].pointerToPageTableEntry[3].frameNumber << endl;
for (int i = 0; i < 4; i++) {
if (segTables[0].pointerToSegmentEntry[2].pointerToPageTable[2].pointerToPageTableEntry[3].frameNumber == i) {
}
else {
segTables[0].pointerToSegmentEntry[2].pointerToPageTable[2].pointerToPageTableEntry[3].frameNumber = i;
break;
}
}
getchar();
}
Explanation / Answer
In this way you can use vector instead of pointer. Think of it as n-dimensional array. Thats all. Its like there is big box , in that box there is another small box and in that small box there is another smallest box.
So in above solution
vector<pair<string, int>> - this is basically a page table or array of page table entry. C++ provide pair which you read in its documentation. Instead of that you can struct too.
Now vector<vector<pair<string, int>>> this is basically the array of page table or segment table entry. So we are communicating to compiler and saying please create n * page table, means each indexes will point to vector<pair<string, int> > similarly for segment table.
Note-
Don't forget to give space in ending angle bracket(>) . In new c++ version there is no need but in previous version it get ambiguous and find it right shift operator(>>). So better be safe. If you have any doubt please ask me.
Next time please explain the input clearly. It makes easy for us to understand what you want to do. Like its difficult to understand how input is working
process 0 0x3 its not clear.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.