public int createTable() { int current = machine.memoryManagement.alloc(17); if (current == 0) return 0; PagerHeader currentHeader = new PagerHeader(current, 0, 0); if (first == 0) { first = last = current; } else { PagerHeader ph = getHeader(last); ph.next = current; setHeader(ph); last = current; } setHeader(currentHeader); clearPage(current); return current; }
public void freePage(int adr) { for (int i = 0; i < 16; i++) machine.memoryManagement.free(machine.ram[adr + i]); PagerHeader ph = getHeader(adr); PagerHeader next = null; PagerHeader prev = null; if (ph.next > 0) next = getHeader(ph.next); if (ph.prev > 0) prev = getHeader(ph.prev); if (first == last && first == adr) { first = last = 0; } else if (first == adr) { first = next.adr; next.prev = 0; setHeader(next); } else if (adr == last) { last = prev.adr; prev.next = 0; setHeader(prev); } else { prev.next = next.adr; next.prev = prev.adr; setHeader(next); setHeader(prev); } machine.memoryManagement.free(adr); }