LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
lineGetAvailableMemory.m
1function bytes = lineGetAvailableMemory()
2% LINEGETAVAILABLEMEMORY Portable available-physical-memory probe (bytes).
3%
4% Routes through the JVM OperatingSystemMXBean that MATLAB ships on every
5% platform, so the same code path returns a valid figure on Windows, macOS
6% and Linux without parsing /proc. Falls back to a conservative constant if
7% the bean or method is unavailable (e.g. MATLAB started with -nojvm).
8%
9% Mirrors jline.solvers.ctmc.MemoryGuard.getAvailableMemoryBytes (JAR) and
10% line_solver ... memory_guard.get_available_memory_bytes (Python native).
11
12FALLBACK_BYTES = 1 * 1024^3; % 1 GB
13bytes = FALLBACK_BYTES;
14
15try
16 osb = java.lang.management.ManagementFactory.getOperatingSystemMXBean();
17 v = -1;
18 % JDK <= 13: getFreePhysicalMemorySize; JDK >= 14: getFreeMemorySize
19 try
20 v = osb.getFreePhysicalMemorySize();
21 catch
22 try
23 v = osb.getFreeMemorySize();
24 catch
25 v = -1;
26 end
27 end
28 if ~isempty(v) && v > 0
29 bytes = double(v);
30 end
31catch
32 % leave fallback
33end
34end
Definition Station.m:245