File tree Expand file tree Collapse file tree 6 files changed +54
-60
lines changed Expand file tree Collapse file tree 6 files changed +54
-60
lines changed Original file line number Diff line number Diff line change 1+ function y = is_symlink(p )
2+
3+ try
4+ if stdlib .dotnet_api() >= 6
5+ y = ~isempty(System .IO .FileInfo(p ).LinkTarget);
6+ else
7+ attr = string(System .IO .File .GetAttributes(p ).ToString());
8+ % https://learn.microsoft.com/en-us/dotnet/api/system.io.fileattributes
9+ % ReparsePoint is for Linux, macOS, and Windows
10+ y = contains(attr , ' ReparsePoint' );
11+ end
12+ catch e
13+ switch e .identifier
14+ case {' MATLAB:NET:CLRException:CreateObject' , ' MATLAB:NET:CLRException:MethodInvoke' }
15+ y = false ;
16+ otherwise , rethrow(e )
17+ end
18+ end
19+
20+ end
Original file line number Diff line number Diff line change 1+ function bytes = ram_free()
2+
3+ if ispc()
4+ cmd = ' pwsh -c "(Get-CimInstance -ClassName CIM_OperatingSystem).FreePhysicalMemory * 1KB"' ;
5+ elseif ismac()
6+ cmd = ' sysctl -n hw.memsize' ;
7+ else
8+ cmd = " free -b | awk '/Mem:/ {print $4}'" ;
9+ end
10+
11+ [s , m ] = system(cmd );
12+ if s == 0
13+ bytes = str2double(m );
14+ end
15+
16+ end
Original file line number Diff line number Diff line change 1+ function bytes = ram_total()
2+
3+ if ispc()
4+ cmd = ' pwsh -c "(Get-CimInstance -ClassName Win32_ComputerSystem).TotalPhysicalMemory"' ;
5+ elseif ismac()
6+ cmd = ' sysctl -n hw.memsize' ;
7+ else
8+ cmd = " free -b | awk '/Mem:/ {print $4}'" ;
9+ end
10+
11+ [s , m ] = system(cmd );
12+ if s == 0
13+ bytes = str2double(m );
14+ end
15+
16+ end
Original file line number Diff line number Diff line change 1111 switch e .identifier
1212 case " MATLAB:UndefinedFunction"
1313 if stdlib .has_dotnet()
14- ok = is_symlink_dotnet (p );
14+ ok = stdlib . dotnet .is_symlink (p );
1515 elseif stdlib .has_java()
1616 ok = java .nio .file .Files .isSymbolicLink(javaPathObject(stdlib .absolute(p )));
1717 elseif stdlib .has_python()
3333end
3434
3535
36- function y = is_symlink_dotnet(p )
37-
38- try
39- if stdlib .dotnet_api() >= 6
40- y = ~isempty(System .IO .FileInfo(p ).LinkTarget);
41- else
42- attr = string(System .IO .File .GetAttributes(p ).ToString());
43- % https://learn.microsoft.com/en-us/dotnet/api/system.io.fileattributes
44- % ReparsePoint is for Linux, macOS, and Windows
45- y = contains(attr , ' ReparsePoint' );
46- end
47- catch e
48- switch e .identifier
49- case {' MATLAB:NET:CLRException:CreateObject' , ' MATLAB:NET:CLRException:MethodInvoke' }
50- y = false ;
51- otherwise , rethrow(e )
52- end
53- end
54-
55- end
56-
57-
5836% !test
5937% ! if !ispc
6038% ! p = tempname();
Original file line number Diff line number Diff line change 3737end
3838
3939
40- function bytes = ram_free_system()
41-
42- if ispc()
43- cmd = ' pwsh -c "(Get-CimInstance -ClassName CIM_OperatingSystem).FreePhysicalMemory * 1KB"' ;
44- elseif ismac()
45- cmd = ' sysctl -n hw.memsize' ;
46- else
47- cmd = " free -b | awk '/Mem:/ {print $4}'" ;
48- end
49-
50- [s , m ] = system(cmd );
51- if s == 0
52- bytes = str2double(m );
53- end
54-
55- end
56-
57-
5840function bytes = ram_free_java()
5941
6042b = javaMethod(" getOperatingSystemMXBean" , " java.lang.management.ManagementFactory" );
Original file line number Diff line number Diff line change 1919end
2020
2121if bytes <= 0
22- bytes = ram_total_system ();
22+ bytes = stdlib . sys .ram_total ();
2323end
2424
2525bytes = uint64(bytes );
2626
2727end
2828
2929
30- function bytes = ram_total_system()
31-
32- if ispc()
33- cmd = ' pwsh -c "(Get-CimInstance -ClassName Win32_ComputerSystem).TotalPhysicalMemory"' ;
34- elseif ismac()
35- cmd = ' sysctl -n hw.memsize' ;
36- else
37- cmd = " free -b | awk '/Mem:/ {print $4}'" ;
38- end
39-
40- [s , m ] = system(cmd );
41- if s == 0
42- bytes = str2double(m );
43- end
44-
45- end
46-
47-
4830function bytes = ram_total_java()
4931% https://docs.oracle.com/en/java/javase/21/docs/api/jdk.management/com/sun/management/OperatingSystemMXBean.html#getTotalMemorySize()
5032
You can’t perform that action at this time.
0 commit comments