Skip to content

Commit 13721a4

Browse files
committed
sys.ram* more accurate
1 parent 7b650a3 commit 13721a4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

+stdlib/+sys/ram_free.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
if ispc()
66
cmd = 'pwsh -c "(Get-CimInstance -ClassName CIM_OperatingSystem).FreePhysicalMemory * 1KB"';
77
elseif ismac()
8-
cmd = 'sysctl -n hw.memsize';
8+
cmd = 'sysctl -n vm.page_free_count';
99
else
1010
cmd = "free -b | awk '/Mem:/ {print $4}'";
1111
end
1212

1313
[s, m] = system(cmd);
1414
if s == 0
1515
bytes = str2double(m);
16+
if ismac()
17+
bytes = bytes * 4096; % Assuming a page size of 4096 bytes
18+
end
19+
1620
end
1721

1822
bytes = uint64(bytes);

+stdlib/+sys/ram_total.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
elseif ismac()
88
cmd = 'sysctl -n hw.memsize';
99
else
10-
cmd = "free -b | awk '/Mem:/ {print $4}'";
10+
cmd = "free -b | awk '/Mem:/ {print $2}'";
1111
end
1212

1313
[s, m] = system(cmd);

0 commit comments

Comments
 (0)