-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathunit1.pas
More file actions
241 lines (217 loc) · 6.78 KB
/
unit1.pas
File metadata and controls
241 lines (217 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
(******************************************************************************)
(* RAM-User 11.07.2025 *)
(* *)
(* Version : 0.01 *)
(* *)
(* Author : Uwe Schächterle (Corpsman) *)
(* *)
(* Support : www.Corpsman.de *)
(* *)
(* Description : Application to allocate RAM *)
(* *)
(* License : See the file license.md, located under: *)
(* https://github.com/PascalCorpsman/Software_Licenses/blob/main/license.md *)
(* for details about the license. *)
(* *)
(* It is not allowed to change or remove this text from any *)
(* source file of the project. *)
(* *)
(* Warranty : There is no warranty, neither in correctness of the *)
(* implementation, nor anything other that could happen *)
(* or go wrong, use at your own risk. *)
(* *)
(* Known Issues: none *)
(* *)
(* History : 0.01 - Initial version *)
(* *)
(******************************************************************************)
Unit Unit1;
{$MODE objfpc}{$H+}
Interface
Uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls;
Type
{ TForm1 }
TForm1 = Class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
CheckBox1: TCheckBox;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
Timer1: TTimer;
Procedure Button1Click(Sender: TObject);
Procedure Button2Click(Sender: TObject);
Procedure Button3Click(Sender: TObject);
Procedure Edit1Change(Sender: TObject);
Procedure FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
Procedure FormCreate(Sender: TObject);
Procedure Timer1Timer(Sender: TObject);
private
fBlocks: Array Of Array Of Byte;
fBlockIndex, fBlocksize, fBlockCount: Integer;
Procedure updateRAMUsageInfo;
public
End;
Var
Form1: TForm1;
Implementation
Uses math;
{$R *.lfm}
Function FileSizeToString(Value: Int64): String;
Var
s: char;
r: Int64;
Begin
s := ' ';
r := 0;
If value >= 1000 Then Begin
s := 'K';
r := value Mod 1000;
value := value Div 1000;
End;
If value >= 1000 Then Begin
s := 'M';
r := value Mod 1000;
value := value Div 1000;
End;
If value >= 1000 Then Begin
s := 'G';
r := value Mod 1000;
value := value Div 1000;
End;
If value >= 1000 Then Begin
s := 'T';
r := value Mod 1000;
value := value Div 1000;
End;
If value >= 1000 Then Begin
s := 'P';
r := value Mod 1000;
value := value Div 1000;
End;
If (r Div 100) <> 0 Then Begin
value := value * 10 + round(r / 100);
result := format('%0.1f%sB', [value / 10, s]);
End
Else
result := inttostr(value) + s + 'B'
End;
{ TForm1 }
Procedure TForm1.Button3Click(Sender: TObject);
Begin
Button2Click(Nil);
close;
End;
Procedure TForm1.Edit1Change(Sender: TObject);
Var
Blocksize, BlockCount: Integer;
Begin
Blocksize := strtointdef(edit1.text, 0);
BlockCount := strtointdef(edit2.text, 0);
label5.caption := FileSizeToString(Blocksize * BlockCount);
End;
Procedure TForm1.FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
Begin
Button2Click(Nil);
End;
Procedure TForm1.FormCreate(Sender: TObject);
Begin
Randomize;
(*
* History: 0.01 = Initialversion (11.07.2025)
*)
caption := 'RAM user, by Corpsman ver 0.01';
edit1.text := '1048576'; // 1 MB
// edit1.text := '20971520'; // 20 MB
edit2.text := '1024';
edit3.text := '10';
label7.caption := '';
fBlocks := Nil;
End;
Procedure TForm1.Timer1Timer(Sender: TObject);
Var
j: Integer;
Begin
If fBlockIndex <= high(fBlocks) Then Begin
setlength(fBlocks[fBlockIndex], fBlocksize);
If CheckBox1.Checked Then Begin
For j := 0 To high(fBlocks[fBlockIndex]) Do Begin
fBlocks[fBlockIndex, j] := Random(256);
End;
End;
fBlockIndex := fBlockIndex + 1;
updateRAMUsageInfo;
End
Else Begin
Timer1.Enabled := false;
End;
End;
Procedure TForm1.updateRAMUsageInfo;
Var
i: integer;
s: UInt64;
Begin
s := length(fBlocks) * 4;
For i := 0 To high(fBlocks) Do Begin
s := s + length(fBlocks[i]);
End;
label7.caption := FileSizeToString(s);
End;
Procedure TForm1.Button2Click(Sender: TObject);
Var
i: Integer;
Begin
// Free
Button1.Enabled := true;
Button2.Enabled := false;
Timer1.Enabled := false;
For i := 0 To high(fBlocks) Do Begin
setlength(fBlocks[i], 0);
End;
setlength(fBlocks, 0);
label7.caption := '';
End;
Procedure TForm1.Button1Click(Sender: TObject);
Var
i, Delta, j: integer;
Begin
fBlocksize := strtointdef(edit1.text, 0);
fBlockCount := strtointdef(edit2.text, 0);
// Allocate
Button1.Enabled := false;
If RadioButton1.Checked Then Begin
// Instant
setlength(fBlocks, fBlockCount);
For i := 0 To fBlockCount - 1 Do Begin
setlength(fblocks[i], fBlocksize);
If CheckBox1.Checked Then Begin
For j := 0 To high(fBlocks[i]) Do Begin
fBlocks[i, j] := Random(256);
End;
End;
End;
updateRAMUsageInfo;
End
Else Begin
// Over Time
Delta := max(10, strtointdef(edit3.text, 100));
Timer1.Interval := Delta;
Timer1.Enabled := true;
setlength(fBlocks, fBlockCount);
fBlockIndex := 0;
End;
Button2.Enabled := true;
End;
End.