C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 20th, 2013, 02:03 PM
blackvelvet blackvelvet is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 blackvelvet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 39 sec
Reputation Power: 0
General - What is the best way to write a page replacement algorithm (FIFO, MRU, LRU, Optimal)

So I have a vector of numbers, say: 5, 6, 8, 2, 3, 1, 4, etc...

And the number of frames is: 4

What is the best type of data structure to use to write a page replacement algorithm (FIFO, MRU, LRU, and Optimal) to find the number of page faults?

I've tried writing some code for the FIFO algorithm, but it's so messy, disorganized, hard to read, and I don't think even works properly...

Code:
void FIFO(vector<int> virtualPageVector, int numOfFrames)
{

int FIFOarray[numOfFrames];
int pageFaults = 0;
int firstIn = 1;
int pf = 0;
int round = 0;

for(unsigned int i = 0;i < virtualPageVector.size();i++)
{
    if(numOfFrames > i)
    {
        FIFOarray[i] = virtualPageVector[i];
        cout << FIFOarray[i] << endl;
        pageFaults++;
    }
    if(i >= numOfFrames)
    {
        for(int j = 0; j <= numOfFrames;j++)
        {
            if(FIFOarray[j] == virtualPageVector[i])
            {
                pf = -1;
                round++;
                break;
            }
        }
        if(pf == 0)
        {
            FIFOarray[firstIn] = virtualPageVector[i];
            cout << FIFOarray[firstIn] << endl;
            pageFaults++;
            round = 0;
        }

        if(round > 1)
        {
            firstIn++;
        }
        pf = 0;

        if(firstIn > numOfFrames)
        {
            firstIn = 1;
        }
    }
}
cout << "Page Faults: " << pageFaults << endl;
}


What is a better way to do this, or how would I fix this?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > General - What is the best way to write a page replacement algorithm (FIFO, MRU, LRU, Optimal)


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap