I've been working on getting an LRU algorithm working correctly, but it seems no matter what I try, it keeps performing as well, if not worse, than my FIFO implementation. I really don't know what is wrong with this thing and it's got me quite frustrated. Part of me wants to just abandon what I have and restart, but that would be 4th time I've rewritten this thing and I just need to get it done. If someone can give me some pointers as to what's going wrong that would be awesome:
One possible problem is that your frame array is not ordered.
As a consequence every time you have a page fault you have to scan through your entire array to find the LRU.
Maybe you could try to reorder your array at every operation. Basically you'd only have to shift a number of elements 1 slot to the right and insert an element in the 1st position.
It would have a cost, but you would not have to search for the LRU anymore.
Also, a data structure with fast insertion and deletion of elements might be more efficient than an array for doing this.
Well I'm not concerned with speed of it as I'm working with a small data set. I'm concerned with it reporting the wrong number of page faults for a given reference string.