Skip to content

Commit 4fccef1

Browse files
committed
ram_{free,total}: system fallback if other fails
1 parent ca66879 commit 4fccef1

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

+stdlib/ram_free.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@
2020

2121
function bytes = ram_free()
2222

23+
bytes = 0;
24+
2325
if stdlib.has_java()
2426
bytes = ram_free_java();
2527
elseif stdlib.has_python()
2628
bytes = py_ram_free();
27-
else
29+
end
30+
31+
if bytes <= 0
2832
bytes = ram_free_system();
2933
end
3034

+stdlib/ram_total.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88

99
function bytes = ram_total()
1010

11+
bytes = 0;
1112

1213
if stdlib.dotnet_api() >= 6
1314
% .NET is 2-3x faster than Java for this
1415
% https://learn.microsoft.com/en-us/dotnet/api/system.gcmemoryinfo.totalavailablememorybytes
1516
bytes = System.GC.GetGCMemoryInfo().TotalAvailableMemoryBytes;
1617
elseif stdlib.has_java()
1718
bytes = ram_total_java();
18-
else
19+
end
20+
21+
if bytes <= 0
1922
bytes = ram_total_system();
2023
end
2124

0 commit comments

Comments
 (0)