分组关联的Cache-存储器映象的替换算法
//组中检查位use[i]为 0 的 那块将被用来替换(如果需要的话) // 检查位use[i]的修改在Cache中该块 k 被引用时 visit(k) 发生 //----------- int m; //组中有多少块 int k; //组中哪一块被引用 int use[m]; //将检查位初始化为一个默认的替换优先级序列 for(int i=0;i<m;i++){ use[i]=i; //the most recently used's priority is m-1; //the least recently used's priority is 0 } int visit(k) { int i; // 0<i<m for(i=0;i<m;i++){ if(use[i]<use[k]){} else if (i==k){ use[k]=m-1;} // the last visit ,the highest priority } else{ use[i]--; } } }

|