public void allocate(bool method) { print(); if (method) { sizeCompare a = new sizeCompare(); Form2.memoryList.Sort(a); } else { addressCompare a = new addressCompare(); Form2.memoryList.Sort(a); } for (int j = 0; j < Form2.processesList.Count(); j++) { if (method) { sizeCompare b = new sizeCompare(); Form2.memoryList.Sort(b); } for (int i = 0; i < Form2.memoryList.Count(); i++) { if ((!Form2.memoryList[i].isBlocked) && !Form2.memoryList[i].isUsed && Form2.memoryList[i].size >= Form2.processesList[j].size) { int diff = Form2.memoryList[i].size - Form2.processesList[j].size; Form2.memoryList[i].isUsed = true; Form2.memoryList[i].size = Form2.processesList[j].size; Form2.memoryList[i].id = Form2.processesList[j].id; if (diff > 0) { MemoryLocation newlocation = new MemoryLocation(); newlocation.isUsed = false; newlocation.size = diff; newlocation.id = -1; newlocation.startAddress = Form2.memoryList[i].startAddress + Form2.memoryList[i].size; Form2.memoryList.Insert(i + 1, newlocation); } break; } } print(); } }
public void addblock() { addressCompare a = new addressCompare(); Form2.memoryList.Sort(a); addholes(); int diff2 = 0; for (int i = 1; i < Form2.memoryList.Count(); i++) { diff2 = (Form2.memoryList[i - 1].startAddress + Form2.memoryList[i - 1].size); if (Form2.memoryList[i].startAddress > diff2) { MemoryLocation block = new MemoryLocation(); block.startAddress = diff2; block.size = Form2.memoryList[i].startAddress - diff2; block.isBlocked = true; block.id = -2; Form2.memoryList.Insert(i, block); } } }
void next_Click(object sender, EventArgs e) { bool flag = false; for (int i = 0; i < Form1.inputHolesNum; i++) { MemoryLocation nextlocation = new MemoryLocation(); int size; bool issize = Int32.TryParse(pnlContent.GetControlFromPosition(2, i + 1).Text, out size); if (issize && size >= 0) { nextlocation.size = size; } else { MessageBox.Show("Please enter a correct size.", "Error!", MessageBoxButtons.OK); flag = true; } nextlocation.isUsed = false; int startaddress; bool isstartaddress = Int32.TryParse(pnlContent.GetControlFromPosition(1, i + 1).Text, out startaddress); if (isstartaddress && startaddress >= 0) { nextlocation.startAddress = startaddress; } else { MessageBox.Show("Please enter a correct starting address.", "Error!", MessageBoxButtons.OK); flag = true; } nextlocation.id = -1; memoryList.Add(nextlocation); } for (int i = 0; i < Form1.inputProcessesNum; i++) { MemoryLocation nextprocess = new MemoryLocation(); int size; bool issize = Int32.TryParse(pnlContent.GetControlFromPosition(7, i + 1).Text, out size); if (issize && size >= 0) { nextprocess.size = size; } else { MessageBox.Show("Please enter a correct size.", "Error!", MessageBoxButtons.OK); flag = true; } nextprocess.id = i; nextprocess.isUsed = true; processesList.Add(nextprocess); } if (!flag) { Form3 f = new Form3(); f.ShowDialog(); } }