-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMaxLogic.MemoryUsageInfo.pas
More file actions
61 lines (49 loc) · 1.29 KB
/
Copy pathMaxLogic.MemoryUsageInfo.pas
File metadata and controls
61 lines (49 loc) · 1.29 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
Unit MaxLogic.MemoryUsageInfo;
Interface
Uses
windows, sysUtils, classes, Winapi.PsAPI;
// FastMM4 memory info
Function CurrentMemoryUsage: int64;
Function GetCurMemoryUsageStr: String;
Function fstr(Const d: double; vs: byte = 2; ns: byte = 2): String;
Implementation
Function CurrentMemoryUsage: int64;
Var
st: TMemoryManagerState;
sb: TSmallBlockTypeState;
Begin
GetMemoryManagerState(st);
Result := st.TotalAllocatedMediumBlockSize + st.TotalAllocatedLargeBlockSize;
For sb In st.SmallBlockTypeStates Do
Result := Result + sb.UseableBlockSize * sb.AllocatedBlockCount;
End;
Function GetCurMemoryUsageStr: String;
Var
Cur, reserved, max: int64;
s: String;
pmc: TProcessMemoryCounters;
Begin
Cur := CurrentMemoryUsage;
If GetProcessMemoryInfo(GetCurrentProcess, @pmc, sizeOf(pmc)) Then
Begin
max := pmc.PeakWorkingSetSize;
reserved := pmc.WorkingSetSize;
End
Else
Begin
max := 0;
reserved := 0;
End;
s := Format('Memory usage: %s MB by FastMM4 (reserved: %s, max: %s MB)',
[fstr(Cur / 1024 / 1024), fstr(reserved / 1024 / 1024),
fstr(max / 1024 / 1024)]);
Result := s;
End;
Function fstr(Const d: double; vs: byte = 2; ns: byte = 2): String;
Var
s: String;
Begin
s := '0.' + StringOfChar('0', ns);
Result := FormatFloat(s, d);
End;
end.