26
26
' WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
27
'
28
28
# If TARGET_JVM = False Then 'OSVersion Not Supported by Grasshopper
29
+ Imports System.ComponentModel
29
30
Imports System.Globalization
30
31
Imports System.Diagnostics
32
+ Imports System.Runtime.InteropServices
31
33
32
34
Namespace Microsoft.VisualBasic.Devices
33
35
<DebuggerTypeProxy( GetType (ComputerInfo.ComputerInfoDebugView))> _
@@ -36,17 +38,56 @@ Namespace Microsoft.VisualBasic.Devices
36
38
'Empty
37
39
End Sub
38
40
41
+ Private Function IsOnWindows() As Boolean
42
+ Return Environment.OSVersion.Platform <> PlatformID.Unix AndAlso Environment.OSVersion.Platform <> 128
43
+ End Function
44
+
45
+ <StructLayout(LayoutKind.Sequential)>
46
+ Private Structure MEMORYSTATUSEX
47
+ Public dwLength As Integer
48
+ Public dwMemoryLoad As Integer
49
+ Public ullTotalPhys As ULong
50
+ Public ullAvailPhys As ULong
51
+ Public ullTotalPageFile As ULong
52
+ Public ullAvailPageFile As ULong
53
+ Public ullTotalVirtual As ULong
54
+ Public ullAvailVirtual As ULong
55
+ Public ullAvailExtendedVirtual As ULong
56
+ End Structure
57
+
58
+ <DllImport( "kernel32" , CallingConvention:=CallingConvention.StdCall)>
59
+ Private Shared Function GlobalMemoryStatusEx( ByRef buf As MEMORYSTATUSEX) As Boolean
60
+ End Function
61
+
62
+ Private Function GetMemoryInfo() As MEMORYSTATUSEX
63
+ Dim buf As New MEMORYSTATUSEX()
64
+ buf.dwLength = Marshal.SizeOf(buf)
65
+ If GlobalMemoryStatusEx(buf) Then
66
+ Return buf
67
+ Else
68
+ Throw New Win32Exception()
69
+ End If
70
+ End Function
71
+
39
72
<CLSCompliant( False )> _
40
73
Public ReadOnly Property AvailablePhysicalMemory() As ULong
41
74
Get
42
- Throw New NotImplementedException()
75
+ If IsOnWindows() Then
76
+ Return GetMemoryInfo().ullAvailPhys
77
+ Else
78
+ Throw New NotImplementedException()
79
+ End If
43
80
End Get
44
81
End Property
45
82
46
83
<CLSCompliant( False )> _
47
84
Public ReadOnly Property AvailableVirtualMemory() As ULong
48
85
Get
49
- Throw New NotImplementedException()
86
+ If IsOnWindows() Then
87
+ Return GetMemoryInfo().ullAvailVirtual
88
+ Else
89
+ Throw New NotImplementedException()
90
+ End If
50
91
End Get
51
92
End Property
52
93
@@ -77,14 +118,22 @@ Namespace Microsoft.VisualBasic.Devices
77
118
<CLSCompliant( False )> _
78
119
Public ReadOnly Property TotalPhysicalMemory() As ULong
79
120
Get
80
- Throw New NotImplementedException()
121
+ If IsOnWindows() Then
122
+ Return GetMemoryInfo().ullTotalPhys
123
+ Else
124
+ Throw New NotImplementedException()
125
+ End If
81
126
End Get
82
127
End Property
83
128
84
129
<CLSCompliant( False )> _
85
130
Public ReadOnly Property TotalVirtualMemory() As ULong
86
131
Get
87
- Throw New NotImplementedException()
132
+ If IsOnWindows() Then
133
+ Return GetMemoryInfo().ullTotalVirtual
134
+ Else
135
+ Throw New NotImplementedException()
136
+ End If
88
137
End Get
89
138
End Property
90
139
0 commit comments