As the title says, I'm working on implementing a few of the major page replacement algorithms using an artificially generated reference string and random number of frames. Anyways, for frame number n, there's going to be the initial n page faults (demand paging). I'm having trouble thinking of a way to implement this. Would I just do a straight search in my frame array for the given reference number? That'll make it fault, but searching an empty array seems silly. Any advice?
I'm stuck trying to figure out how to stick new pages in. The way I have it right now will work when frameV is full, but if not then I don't see it working. For example, if frameV is only half full and a new page comes in that isn't in there, it might just replace one of the spots with a page already because it's just checking times, and I don't know how that'll work for empty array spots. This is my third iteration of programs I've written to do this, and I always hit these problems.
inlinebool pageFault(frame frameV, int ref, int sz)
for(int i = 0; i < sz; i++)
if(frameV[i].pageRef == ref)
I have a 20 digit reference string generated randomly, with 7 frames. First time it faulted 18 times, second time it faulted 17 times. Both were wrong. First should have faulted 9, and second I didn't desk check it. Here's the data I was working with the second time:
Reference string: 67853199045177992171
Number of frames: 7
FIFO Faults: 17
Clearly that's not right -_-
After running through round two on paper, it should have faulted 11 times. As far as I can tell the pageFault() function is fine so I'm assuming the issue lies in my fifo() function
Wow small mistake. Forgot to update my time variable keeping track of the longest in, and had the time check backwards. Works now, if anyone sees anything I can improve on please tell me.