Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > FIFO Anomaly,,

Reply
Thread Tools

FIFO Anomaly,,

 
 
mai
Guest
Posts: n/a
 
      04-15-2007
Hi everyone,
i'm trying to exhibit FIFO anomaly(page replacement algorithm),, I
searched over 2000 random strings but i couldnt find any anomaly,, am
i I doing it right?,, Please help,,,The following is the code,,

#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <ctime> // For time()
#include <cstdlib> // For srand() and rand()
using namespace std;

struct mem
{
int page;
int extr;
};
mem* memArr;
mem temp;
int* refPattern;
int b_val;
int* arra;

// This is a function that counts the page faults
int PageFaultCount(int noframe, int leng_patt){
int page_fault_num = 0;
int i,j,k,x,y,d,c;
int boolValue = 0;
int boo = 0;

memArr = (mem*)malloc(noframe*sizeof(mem));
memArr[0].extr = 1;
memArr[0].page = refPattern[0];
page_fault_num = 1;
d = 1;
c = 1;
while ((c < leng_patt) && (d < noframe)){
boo = 0;
for(k=0; k<d; k++){
if (memArr[k].page == refPattern[c]){
boo++;
}
}
if(boo == 0){
memArr[d].extr = 0;
memArr[d].page = refPattern[c];
page_fault_num++;
for(j=0; j<=d; j++){
memArr[j].extr = memArr[j].extr + 1;
}
d++;
}
c++;
}
while ((c < leng_patt)&&(d == noframe)){

boolValue = 0;
for(j=0; j< noframe; j++){


if (memArr[j].page == refPattern[c]){
boolValue++;
}
}
if(boolValue == 0){
for(x=0 ; x<(noframe-1); x++){
for(y=(x+1) ; y < noframe ; y++){
if(memArr[x].extr > memArr[y].extr){
temp = memArr[x];
memArr[x] = memArr[y];
memArr[y] = temp;
}
}
}
memArr[noframe-1].page = refPattern[c];
memArr[noframe-1].extr = 0;
page_fault_num++;
for(k=0; k < noframe; k++){
memArr[k].extr = memArr[k].extr + 1;
}
}
c++;
}

return page_fault_num;
}
// this is a function that generate random strings
void GenReferencePatternAndCountPageFault(int num_of_frames, int
num_of_pages, int length_of_ref_patt){

int a[20];
int i,j,x,y,k;
int min = 0;

refPattern = (int*)malloc(length_of_ref_patt*sizeof(int));
//create random reference string

for(i=0; i<length_of_ref_patt; i++)
refPattern[i] = (rand()% num_of_pages) + min;

// here i'm trying to save all the page faults in an array
for(j = 1; j<= num_of_frames; j++){
arra[j-1]= PageFaultCount(j ,length_of_ref_patt);

}
// and here im trying to find if a larger frame has larger page
fault to detect the anomaly
for(x=0 ; x<(num_of_frames-1); x++){
for(y=(x+1) ; y < num_of_frames ; y++){
if(a[x] < a[y]){
b_val = 1;


}
}
}



}


int main(){
int ref_pattern_length, page_count,frame_count_limit, j;

int i =1;
b_val = 0;


cout<<"Please enter the value of frame count limit";
cin>> frame_count_limit;
cout<<"Please enter the value page count :";
cin>> page_count;
cout<<"Please enter the length of reference pattern: ";
cin>> ref_pattern_length;
arra = (int*)malloc(frame_count_limit*sizeof(int));

srand(time(0));
while((i<=2000)&&(b_val == 0)){

GenReferencePatternAndCountPageFault(frame_count_l imit,
page_count, ref_pattern_length);
i++;
}
if(b_val == 1){
cout<< "There is a FIFO anomaly
}
else
if(b_val == 0){
cout<<" no anomaly was detected; please try again with different
input \n";}

free(refPattern);
free(arra);
return 0;
}

 
Reply With Quote
 
 
 
 
Howard
Guest
Posts: n/a
 
      04-16-2007

"mai" <> wrote in message
news: ups.com...
> Hi everyone,
> i'm trying to exhibit FIFO anomaly(page replacement algorithm),, I
> searched over 2000 random strings but i couldnt find any anomaly,, am
> i I doing it right?,, Please help,,,The following is the code,,


I'm not sure how many people here would have any idea what a "FIFO anomaly"
is. I sure don't.

We don't know what input you're using, or what you expect the output to be
for any given input. Perhaps you could give us a specific example of some
input, its expected result, and what you're seeing instead. You should also
use a debugger to step through the code and see what it's doing at various
stages. Or add some output statements at various points to report what it's
doing. (Or both.)

-Howard

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FIFO, FIFO, It's Off To Queue We Go... Lawrence D'Oliveiro NZ Computing 7 05-09-2009 08:37 AM
any body having complete code for synchronous fifo or know a link where fifo codes are available plz help chaitu VHDL 1 06-01-2007 07:03 PM
any body having complete code for a synchronous FIFO or know a link where FIFO codes are available chaitu VHDL 1 06-01-2007 03:45 AM
any body having complete code for a synchronous FIFO or know a link where FIFO codes are available chaitu VHDL 1 05-31-2007 03:31 PM
any body having complete code for a synchronous FIFO or know a link where FIFO codes are available chaitu VHDL 0 05-31-2007 02:28 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57