Skip to content

Commit 2afde54

Browse files
author
=
committed
Add memory compaction and updated screenshots/documentation
1 parent 6c46cd5 commit 2afde54

23 files changed

+47
-3
lines changed

memory-allocator-gui-app/MAForm.Designer.cs

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

memory-allocator-gui-app/MAForm.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,29 @@ private void removeHole(int startAddress, int endAddress)
101101
}
102102
}
103103

104+
private void compactMemory()
105+
{
106+
int pc = processes.Count(), accumilatedAddresses = 0;
107+
for (int i = 0, prevProcessEndAddress = 0, processSize = 0; i < pc; i++)
108+
{
109+
prevProcessEndAddress = processes[i].endAddress;
110+
processSize = processes[i].endAddress - processes[i].startAddress;
111+
process tempP = new process();
112+
tempP.name = processes[i].name;
113+
tempP.startAddress = accumilatedAddresses;
114+
tempP.endAddress = accumilatedAddresses + processSize;
115+
processes[i] = tempP;
116+
accumilatedAddresses = processes[i].endAddress;
117+
}
118+
holes = new List<hole>();
119+
hole tempH = new hole();
120+
tempH.startAddress = accumilatedAddresses;
121+
tempH.endAddress = memory_size;
122+
holes.Add(tempH);
123+
draw();
124+
return;
125+
}
126+
104127
private int firstFit(int processSize)
105128
{
106129
int hc = holes.Count();
@@ -310,7 +333,7 @@ private void draw()
310333
if (name != "Hole")
311334
{
312335
lbl.Name = (iProcesses - 1).ToString();
313-
lbl.Click += (s, ea) => {
336+
lbl.DoubleClick += (s, ea) => {
314337
Label temp = (Label)s;
315338
removeProcess(Int32.Parse(temp.Name));
316339
};
@@ -398,7 +421,9 @@ private void submitBtn_Click(object sender, EventArgs e)
398421
worstFitRad.Enabled = true;
399422
worstFitRad.Visible = true;
400423
submitBtn.Text = "Reset";
401-
submitBtn.Location = new Point(316, 90);
424+
submitBtn.Location = new Point(235, 90);
425+
compactBtn.Enabled = true;
426+
compactBtn.Visible = true;
402427
addBtn.Text = "Add Process";
403428
addBtn.Location = new Point(397, 90);
404429

@@ -458,7 +483,7 @@ private void submitBtn_Click(object sender, EventArgs e)
458483
processes.Add(newProcess2);
459484
}
460485
}
461-
else
486+
else if (i != 0)
462487
{
463488
process newProcess = new process();
464489
newProcess.name = "Reserved " + i.ToString();
@@ -513,6 +538,10 @@ private void addBtn_Click(object sender, EventArgs e)
513538
}
514539
}
515540
}
541+
private void compactBtn_Click(object sender, EventArgs e)
542+
{
543+
compactMemory();
544+
}
516545
private void outResizeBar_Scroll(object sender, EventArgs e)
517546
{
518547
draw();

os-memory-allocator-documentation.pdf

132 KB
Binary file not shown.

screenshots/1.png

-296 Bytes
Loading

screenshots/10-1.png

12.2 KB
Loading

screenshots/10-2.png

3.05 KB
Loading

screenshots/11-1.png

12.4 KB
Loading

screenshots/11-2.png

3.21 KB
Loading

screenshots/12-1.png

12.6 KB
Loading

screenshots/12-2.png

3.11 KB
Loading

0 commit comments

Comments
 (0)