How analog virtual storage systems work, replacing with LRU page replacement algorithms

Source: Internet
Author: User

How to simulate virtual storage system, using LRU page replacement algorithm for virtual page substitution

#include <iostream> #include <cstring> #include <algorithm> #include <list> #include <vector  > #define MAX 4//initial maximum number of pages #define N 1024x768 #define HASHX #define Page_size, using namespace std;struct node{int   Addr BOOL had; Effective bit boolused; Using bit}mainaddr[n];list<int>vpage; Virtual page table, mount bit vector<int>ans[n];int n,a[n];int pushpage (int x) {///Virtual page Table push if (vpage.size () ==MAXN) {//Virtual page table full when replace VPa Ge.pop_front (); Vpage.push_back (x); } else{//Virtual page is not full when direct push vpage.push_back (x);}}   void record (int x) {list<int>::iteratorit; For (It=vpage.begin (); It!=vpage.end (); it++) Ans[x].push_back (*it);    } void Output () {cout<< "time:";    for (inti=1;i<=n;++i) cout<<i<< "";    cout<<endl;    cout<< "\ n page:";    for (inti=1;i<=n;++i) cout<<a[i]<< "";    cout<< "\N\NLRU:";       for (Inti=0;i<max;++i) {if (i) cout<< ""; for (INTJ=1;J&LT;=N;++J) {if (Ans[j].size () >i) cout<<ans[j][i]<< "";        else cout<< "";     } cout<<endl; } cout<<endl;     } int main () {cout<< "Enter the number and address stream of the virtual page address stream:" <<endl;    cin>>n;     for (Inti=1;i<=n;++i) cin>>a[i];         for (inti=1;i<=n;++i) {List<int>::iteratorit=find (Vpage.begin (), Vpage.end (), a[i]);      if (It!=vpage.end ()) {//Hit vpage.erase (IT); Pushpage (A[i]);      }else{//Miss Pushpage (A[i]); record (i);      } cout<< Endl;      Output (); return 0;}

  

How analog virtual storage systems work, replacing with LRU page replacement algorithms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.