在本次试验中,个人所用语言为java语言,虽然除了我之外都是清一色的c,不过对于此次试验自己还是比较满意的,代码全部为自己创作,并修改,收获颇多;
public class MainMethod {
List<Entity> list = new ArrayList<Entity>();
public void add(Entity entity) {
this.list.add(entity);
}
public void panduan(String caozuo, int yehao, int dizhi) {
Entity entity= this.listNum(yehao);
if (entity == null) {
System.out.println("产生缺页中断 * " + yehao);
boolean flag = this.isOne(yehao);
int flagToOne = (flag==true)?1:0;
if (flagToOne == 1) {
System.out.println("OUT " + this.list.get(0).getYehao());
System.out.println("IN " + yehao);
System.out.println("******此时所有页面信息为*****");
this.changeAllList(yehao);
this.xianshi();
}else {
//全面修改list;
System.out.println("IN " + yehao);//待修改
System.out.println("******此时所有页面信息为*****");
this.changeAllList(yehao);
this.xianshi();
}
}else {
int fin = entity.getYejiahao() * 1024 + dizhi;
if ("存".equals(caozuo)) {
this.changeSymbol(yehao);//修改标志位为1.
System.out.println("这个页面的物理地址是:"+fin);
System.out.println("******此时所有页面信息为*****");
this.xianshi();
}else {
System.out.println("这个页面的物理地址是:"+fin);
System.out.println("******此时所有页面信息为*****");
this.xianshi();
}
}
}
//返回页表数组.
public Entity listNum(int yehao) {
Entity entity = null;
if (yehao == this.list.get(0).getYehao()) {
entity = new Entity();
entity = this.list.get(0);
}else if (yehao == this.list.get(1).getYehao()) {
entity = new Entity();
entity = this.list.get(1);
}else if (yehao == this.list.get(2).getYehao()) {
entity = new Entity();
entity = this.list.get(2);
}else if (yehao == this.list.get(3).getYehao()) {
entity = new Entity();
entity = this.list.get(3);
}else {
entity = null;
}
return entity;
}
public void changeSymbol(int changeNum) {
Entity entity = this.list.get(changeNum);
entity.setZiygaibiaozhi(1);
}
//判断修改标志是否为1.
public boolean isOne(int yehao) {
boolean flag = false;
Entity entity = this.list.get(0);
int changeSymbol = entity.getZiygaibiaozhi();
if (changeSymbol == 1) {
flag = true;
}
return flag;
}
//全面修改list;
public void changeAllList(int yehao) {
Entity entity_0 = new Entity();
entity_0 = this.list.get(0);
Entity entity = new Entity(yehao, 1, entity_0.getYejiahao(), 0, -1);
this.list.remove(0);
this.list.add(entity);
}
public void xianshi() {
System.out.println("页号 页架号 修改标志");
for (Entity list_i : this.list) {
System.out.println(list_i.getYehao()+" "+list_i.getYejiahao()+" "+list_i.getZiygaibiaozhi());
}
}
}
这是核心代码,在这两次试验中,自己都用的集合框架中的list来盛放创建的对象,应该也可以使用数组来盛放对象,自己随后会不断重构代码,追求效率。