@@ -101,6 +101,29 @@ private void removeHole(int startAddress, int endAddress)
101
101
}
102
102
}
103
103
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
+
104
127
private int firstFit ( int processSize )
105
128
{
106
129
int hc = holes . Count ( ) ;
@@ -310,7 +333,7 @@ private void draw()
310
333
if ( name != "Hole" )
311
334
{
312
335
lbl . Name = ( iProcesses - 1 ) . ToString ( ) ;
313
- lbl . Click += ( s , ea ) => {
336
+ lbl . DoubleClick += ( s , ea ) => {
314
337
Label temp = ( Label ) s ;
315
338
removeProcess ( Int32 . Parse ( temp . Name ) ) ;
316
339
} ;
@@ -398,7 +421,9 @@ private void submitBtn_Click(object sender, EventArgs e)
398
421
worstFitRad . Enabled = true ;
399
422
worstFitRad . Visible = true ;
400
423
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 ;
402
427
addBtn . Text = "Add Process" ;
403
428
addBtn . Location = new Point ( 397 , 90 ) ;
404
429
@@ -458,7 +483,7 @@ private void submitBtn_Click(object sender, EventArgs e)
458
483
processes . Add ( newProcess2 ) ;
459
484
}
460
485
}
461
- else
486
+ else if ( i != 0 )
462
487
{
463
488
process newProcess = new process ( ) ;
464
489
newProcess . name = "Reserved " + i . ToString ( ) ;
@@ -513,6 +538,10 @@ private void addBtn_Click(object sender, EventArgs e)
513
538
}
514
539
}
515
540
}
541
+ private void compactBtn_Click ( object sender , EventArgs e )
542
+ {
543
+ compactMemory ( ) ;
544
+ }
516
545
private void outResizeBar_Scroll ( object sender , EventArgs e )
517
546
{
518
547
draw ( ) ;
0 commit comments