Skip to content

Commit 9ac5773

Browse files
committed
* Implemented RAM Optimizer percentage threshold code
1 parent 9681060 commit 9ac5773

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

MemPlus/Classes/RAM/RamController.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ internal sealed class RamController
5656
/// The list of processes that should be excluded from memory optimisation
5757
/// </summary>
5858
private List<string> _processExceptionList;
59+
/// <summary>
60+
/// An integer value representative of the percentage of RAM usage that should be reached before RAM optimisation should be called
61+
/// </summary>
62+
private double _autoOptimizeRamThreshold;
5963
#endregion
6064

6165
#region Properties
@@ -87,7 +91,10 @@ internal sealed class RamController
8791
/// Property displaying whether the standby cache should be cleared or not during memory optimisation
8892
/// </summary>
8993
internal bool ClearStandbyCache { get; set; }
90-
94+
/// <summary>
95+
/// Property displaying whether automatic RAM optimisation should occur after a certain RAM usage percentage was reached
96+
/// </summary>
97+
internal bool AutoOptimizePercentage { get; set; }
9198
#endregion
9299

93100
/// <summary>
@@ -127,6 +134,12 @@ internal RamController(Dispatcher dispatcher, SfCircularGauge gauge, Label lblTo
127134
_logController.AddLog(new ApplicationLog("Done initializing RamController"));
128135
}
129136

137+
internal void SetAutoOptimizeThreshold(double threshold)
138+
{
139+
if (threshold < 25) throw new ArgumentException("Threshold is dangerously low!");
140+
_autoOptimizeRamThreshold = threshold;
141+
}
142+
130143
/// <summary>
131144
/// Enable or disable automatic timed RAM optimisation
132145
/// </summary>
@@ -278,6 +291,12 @@ private void UpdateRamUsage()
278291
RamUsagePercentage = perc;
279292
RamTotal = total;
280293

294+
if (RamUsagePercentage >= _autoOptimizeRamThreshold && AutoOptimizePercentage)
295+
{
296+
// This is dangerous. Needs to be fixed by checking last call time
297+
ClearMemory();
298+
}
299+
281300
_logController.AddLog(new ApplicationLog("Finished updating RAM usage"));
282301
}
283302
}

MemPlus/Windows/MainWindow.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ internal void LoadProperties()
107107
_ramController.SetRamUpdateTimerInterval(Properties.Settings.Default.RamMonitorInterval);
108108
_ramController.AutoOptimizeTimed(Properties.Settings.Default.AutoOptimizeTimed, Properties.Settings.Default.AutoOptimizeTimedInterval);
109109

110+
_ramController.AutoOptimizePercentage = Properties.Settings.Default.AutoOptimizePercentage;
111+
_ramController.SetAutoOptimizeThreshold(Properties.Settings.Default.AutoOptimizePercentageThreshold);
112+
110113
if (Properties.Settings.Default.RamMonitor)
111114
{
112115
_rmEnabledBeforeInvisible = true;

MemPlus/Windows/SettingsWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
</Grid.ColumnDefinitions>
9191

9292
<CheckBox x:Name="ChbAutoOptimizePercentage" VerticalAlignment="Center" Grid.Row="0" Grid.Column="0" Content="Automatically optimize when RAM usage exceeds" Margin="3"/>
93-
<syncfusion:IntegerTextBox x:Name="ItbAutoOptimizePercentage" Grid.Row="0" Grid.Column="1" Margin="3" />
93+
<syncfusion:IntegerTextBox x:Name="ItbAutoOptimizePercentage" Grid.Row="0" Grid.Column="1" Margin="3" MinValue="25" MaxValue="100"/>
9494
<Label Grid.Row="0" Grid.Column="2" Content="%" Margin="3" />
9595

9696
<CheckBox x:Name="ChbAutoOptimizeTimed" VerticalAlignment="Center" Grid.Row="1" Grid.Column="0" Content="Automatically optimize after" Margin="3"/>

0 commit comments

Comments
 (0)