File tree Expand file tree Collapse file tree 4 files changed +38
-17
lines changed Expand file tree Collapse file tree 4 files changed +38
-17
lines changed Original file line number Diff line number Diff line change 66%
77% %% Outputs
88% * freebytes: free physical RAM [bytes]
9+ %
10+ % This is done using Java on non-Windows platforms.
11+ % VisualBasic (needs Windows) is needed to do this with .NET, so we use builtin memory() on Windows.
912
10- function freebytes = ram_free()
13+ function bytes = ram_free()
1114
1215try
1316 % memory() was added cross-platform to Octave ~ 2021.
1417 % Matlab memory() at least through R2025a is still Windows only.
1518 m = memory();
16- freebytes = m .MemAvailableAllArrays ;
19+ bytes = uint64( m .MemAvailableAllArrays ) ;
1720catch e
1821 switch e .identifier
1922 case {' MATLAB:memory:unsupported' , ' Octave:undefined-function' }
2023 b = javaOSBean();
2124
2225 if stdlib .java_api() < 14
23- freebytes = b .getFreePhysicalMemorySize();
26+ bytes = b .getFreePhysicalMemorySize();
2427 else
25- freebytes = b .getFreeMemorySize();
28+ bytes = b .getFreeMemorySize();
2629 end
30+ bytes = uint64(bytes );
2731 otherwise , rethrow(e )
2832 end
2933end
Original file line number Diff line number Diff line change 99
1010function bytes = ram_total()
1111
12- b = javaOSBean();
12+ % .NET is about 10 times SLOWER than Java
13+ % if ispc() && ~stdlib.isoctave()
14+ % h = NET.addAssembly('Microsoft.VisualBasic');
15+ % ci = Microsoft.VisualBasic.Devices.ComputerInfo();
16+ % bytes = ci.TotalPhysicalMemory;
17+ % delete(h);
18+ % else
19+ b = javaOSBean();
1320
14- if stdlib .java_api() < 14
15- bytes = b .getTotalPhysicalMemorySize();
16- else
17- bytes = b .getTotalMemorySize();
18- end
21+ if stdlib .java_api() < 14
22+ bytes = b .getTotalPhysicalMemorySize();
23+ else
24+ bytes = b .getTotalMemorySize();
25+ end
26+ bytes = uint64(bytes );
27+ % end
1928
2029% https://docs.oracle.com/en/java/javase/21/docs/api/jdk.management/com/sun/management/OperatingSystemMXBean.html#getTotalMemorySize()
2130
Original file line number Diff line number Diff line change @@ -73,12 +73,6 @@ function test_is_parallel(tc)
7373end
7474
7575
76- function test_ram(tc )
77- tc .verifyGreaterThan(stdlib .ram_total(), 0 )
78- tc .verifyGreaterThan(stdlib .ram_free(), 0 )
79- end
80-
81-
8276function test_cpu_count(tc )
8377tc .verifyGreaterThan(stdlib .cpu_count(), 0 )
8478end
Original file line number Diff line number Diff line change @@ -30,13 +30,27 @@ function test_username(tc)
3030tc .verifyGreaterThan(strlength(u ), 0 )
3131end
3232
33-
3433function test_cpu_arch(tc )
3534tc .assumeTrue(ispc() || stdlib .has_java())
3635
3736arch = stdlib .cpu_arch();
3837tc .verifyGreaterThan(strlength(arch ), 0 )
3938end
4039
40+ function test_ram(tc )
41+ tc .assumeTrue(ispc() || stdlib .has_java())
42+
43+ t = stdlib .ram_total();
44+ f = stdlib .ram_free();
45+
46+ tc .verifyGreaterThan(t , 0 )
47+ tc .verifyGreaterThan(f , 0 )
48+
49+ tc .verifyLessThanOrEqual(f , t )
50+
51+ tc .verifyClass(t , ' uint64' )
52+ tc .verifyClass(f , ' uint64' )
53+ end
54+
4155end
4256end
You can’t perform that action at this time.
0 commit comments