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;
} 1 2774
"mai" <to*****@gmail.comwrote in message
news:11**********************@y5g2000hsa.googlegro 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tobias Pfeiffer |
last post by:
Hi!
I want to write a "client-server-application" (only running on the same
machine) or actually I've already begun with and have problems with the
interprocess communication. The server, when...
|
by: Luca |
last post by:
I have the need of a container of integers showing both the
characteristics of an associative container (all integer elements
different from each other) and the FIFO behaviour.
Do you know if...
|
by: worli |
last post by:
Hi All,
I have a strange requirement.
I have a dynamic input numeric data stream e.g. 2, 2, 4, 5 etc....
( each input number range from 1 to 10 ).
lets take a simple case where all inputs will...
|
by: Michele Moccia |
last post by:
How can I implement a "time critical" fifo in c++ ?
I just have to manage sequences of raw bytes, no user defined types.
An std::queue<unsigned char> or std::deque<unsigned char> seems to be slow....
|
by: Jack |
last post by:
I want to implement a fixed-size FIFO queue for characters.
I only want to use array not linked list.
For example,
const int N = 10;
char c_array;
The question is when the queue is full,...
|
by: Dinsdale |
last post by:
I have an application that recieves text data via external input (i.e.
serial) and displays it on the screen (we use carraige return as a
delimiter). At this point I use a regular old text box and...
|
by: Spoon |
last post by:
Hello,
I'm wondering whether the STL defines a data structure with
the following features:
o provides push_front() and pop_back() (like std::list) to
implement a FIFO buffer.
o allows fast...
|
by: doxtor |
last post by:
Hi all..I'm a little bit confuse with this problem.
I have 3 tables, stock_in, stock_level, and stock_out.
stock_in used for save the data product when there's new purchase.
stock_out used for...
|
by: sazd1 |
last post by:
Hi Student2
I am working on similar kind of thing for stock calculation but could not find any solution to my problem even after putting my problem to different forums.
I saw your post that you...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| | |