rss
logo

I provide consulting and custom development for Natural Language Processing, Information Extraction and Search solutions.Self Picture


 learn more   get in touch 

Logo - I Build Search
Mar 20
2003

FIFO Page Replacement Algo digg

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
58
59
60
61
62
63
64
65
66
/* Lab7 - To implement FIFO page replacement algo
 * Pravin Paratey (pravin[AT]iitb.ac.in)
 */
 
#include <stdio.h>
 
 
int FrameBuffer[100][2];
 
int main()
{
	FILE *fp;
	int numFrames;
	int pageHits=0;
	int count=0;
	int pageNum;
	int purgeMem;
	int i;
	int eof;
	int leastUsed=0;
	int leastIndex=0;
 
	fp = fopen("lru.in","r");
	fscanf(fp, "%i", &numFrames);
 
	while(1)
	{
		eof = fscanf(fp, "%i", &pageNum);
		if (eof == -1)
			break;
 
		printf("[%i] Requested\n",pageNum);
		purgeMem=1;
		for(i=0;i<numFrames;i++)
			if (FrameBuffer[i][0] == pageNum)
			{
				pageHits++;
				FrameBuffer[i][1]++;
				purgeMem=0;
				printf("[%i] Found\n",pageNum);
			}
		if (purgeMem)
		{
			leastUsed=100;
			leastIndex=0;
			for(i=0;i<numFrames;i++)
			{
				if(FrameBuffer[i][1] < leastUsed)
				{
					leastUsed=FrameBuffer[i][1];
					leastIndex=i;
				}
			}
			printf("[%i] Not Found ... added -%i- purged\n",pageNum,FrameBuffer[leastIndex][0]);
			FrameBuffer[leastIndex][0] = pageNum;
			FrameBuffer[leastIndex][1] = 0;
		}
		count++;
 
	}
 
	printf("Total pages requested=%i\nPage Hits=%i\nHit Rate=%f",
			count, pageHits, (float)pageHits/(float)count);
	fclose(fp);
	return 0;
}

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Latest Articles

Apr
07

Palindromic sub-sequences in python

This bit of python code returns all palindromic subsequences in the input string.

[Read More]
Feb
19

Join a list of integers in Python

How do you run a string join on a list of integers in Python? After googling for about 10 mins, I gave up and did this. I am sure there is a better way of doing it!

[Read More]

Featured Projects

NLP classes for PHP

NLP classes for PHP

This is an ongoing project to develop a set of classes for Natural Language Processing. Some code would be ported from the NLTK project.

[Read More]

Deebot

Deebot

Deeb0t is an IRC chat bot capable of making meaningful conversation with other users. It also responds to commands issued by its owner.

[Read More]

This page and its contents are copyright © 2010, Pravin Paratey.