Question: Your program is required to read in a text le which contains a description of a reference string that will be simulated. The rst line

Your program is required to read in a text le which contains a description of a reference string that will be
simulated. The rst line gives the number of pages for the system, the second gives the number of frames,
and the third line lists the number of page requests (aka entries) in the reference string. After that, reference
string entries are listed in sequence from 0 to the number indicated. All numbers are positive integers. A
sample data le is attached to this assignment (not the one we will grade with) and an annotated version is
shown below. You may assume that a reference string contains at most 512 entries.
4; number of pages . see canvas for the version of this file you need to support
3; number of frames
7; number of entries in reference string
0;0 th page in reference string
1;1 th page in reference string
2;...
3
3
1
0;6 th page in reference string
// PageTable.h
#ifndef PAGETABLE_H
#define PAGETABLE_H
#include
#include
//enumeration to represent replacement algorithms.
enum replacement_algorithm {
FIFO=0,
LRU,
MFU
};
//forward declarations for structs
struct page_table_entry;
struct page_table;
/**
* Creates a new page table object. Returns a pointer to created page table.
*
* @param page_count Number of pages.
* @param frame_count Numbers of frames.
* @param algorithm Page replacement algorithm
* @param verbose Enables showing verbose table contents.
* @return A page table object.
*/
struct page_table* page_table_create(int page_count, int frame_count, enum replacement_algorithm algorithm, int verbose);
/**
* Destorys an existing page table object. Sets outside variable to NULL.
*
* @param pt A page table object.
*/
void page_table_destroy(struct page_table** pt);
/**
* Simulates an instruction accessing a particular page in the page table.
*
* @param pt A page table object.
* @param page The page being accessed.
*/
void page_table_access_page(struct page_table *pt, int page);
/**
* Displays page table replacement algorithm, number of page faults, and the
* current contents of the page table.
*
* @param pt A page table object.
*/
void page_table_display(struct page_table* pt);
/**
* Displays the current contents of the page table.
*
* @param pt A page table object.
*/
void page_table_display_contents(struct page_table *pt);
#endif
// DataLoader.h
#ifndef FILELOADER_H
#define FILELOADER_H
#include
#include
//structs
struct test_scenario {
int refstr_len;
int refstr[512];
int page_count;
int frame_count;
};
/**
* Loads a test_scenario strut from a textfile.
*
* @param filename The name of the file to load.
* @return A struct containing the loaded file.
*/
struct test_scenario* load_test_data(char* filename);
#endif
//simulator.c
#include
#include
#include "DataLoader.h"
#include "PageTable.h"
int main(int argc, char* argv[]){
char* filename = argv[2];
struct test_scenario* data = load_test_data(filename);
struct page_table* pt_fifo = page_table_create(data->page_count, data->frame_count, FIFO, 0);
struct page_table* pt_lru = page_table_create(data->page_count, data->frame_count, LRU, 0);
struct page_table* pt_mfu = page_table_create(data->page_count, data->frame_count, MFU, 0);
//simulate page requests: fifo
for (int i =0; i < data->refstr_len; i++){
page_table_access_page(pt_fifo, data->refstr[i]);
//page_table_display_contents(pt_fifo);
}
page_table_display(pt_fifo);
//simulate page requests: lru
for (int i =0; i < data->refstr_len; i++){
page_table_access_page(pt_lru, data->refstr[i]);
//page_table_display_contents(pt_lru);
}
page_table_display(pt_lru);
//simulate page requests: mfu
for (int i =0; i < data->refstr_len; i++){
page_table_access_page(pt_mfu, data->refstr[i]);
//page_table_display_contents(pt_mfu);
}
page_table_display(pt_mfu);
page_table_destroy(&pt_fifo);
page_table_destroy(&pt_lru);
page_table_destroy(&pt_mfu);
free(data);
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!