I currently have an array of a custom class which looks like:
Phy[] memory = new Phy[256];
Within my Phy
class I have the following functions:
- Get time stamp (Returns time stamp)
- Update time stamp (Use system time, gets the ms since 1970 and sets it)
When it comes to the LRU part to find the LRU class I do:
public int getLeastRecentlyUsed(){
long leastUsed = memory[0].getTimeStamp();
int leastUsedPosition = 0;
for(int i = 0; i < memory.length; i++){
if(memory[i].getTimeStamp() < leastUsed){
leastUsed = memory[i].getTimeStamp();
leastUsedPosition = i;
}
}
return leastUsedPosition;
}
Which basically looks for the oldest time stamp.
The problem I have just realised is that the processor can do many of these operations in a MS leaving with a useless algorithm.
What can I do to sort this?