Changed the RAM implementation (removed Microsoft.VisualBasic dependency which is not implemented in Mono) and added code to prevent RAM hardware from loading on Linux.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2012 Michael Möller <mmoeller@openhardwaremonitor.org>
11 using System.Runtime.InteropServices;
13 namespace OpenHardwareMonitor.Hardware.RAM {
14 internal class GenericRAM : Hardware {
16 private Sensor loadSensor;
17 private Sensor availableMemory;
19 public GenericRAM(string name, ISettings settings)
20 : base(name, new Identifier("ram"), settings)
22 loadSensor = new Sensor("Memory", 0, SensorType.Load, this, settings);
23 ActivateSensor(loadSensor);
25 availableMemory = new Sensor("Available Memory", 0, SensorType.Data, this,
27 ActivateSensor(availableMemory);
30 public override HardwareType HardwareType {
32 return HardwareType.RAM;
36 public override void Update() {
37 NativeMethods.MemoryStatusEx status = new NativeMethods.MemoryStatusEx();
38 status.Length = checked((uint)Marshal.SizeOf(
39 typeof(NativeMethods.MemoryStatusEx)));
41 if (!NativeMethods.GlobalMemoryStatusEx(ref status))
44 loadSensor.Value = 100.0f -
45 (100.0f * status.AvailablePhysicalMemory) /
46 status.TotalPhysicalMemory;
48 availableMemory.Value = (float)status.AvailablePhysicalMemory /
52 private class NativeMethods {
53 [StructLayout(LayoutKind.Sequential)]
54 public struct MemoryStatusEx {
56 public uint MemoryLoad;
57 public ulong TotalPhysicalMemory;
58 public ulong AvailablePhysicalMemory;
59 public ulong TotalPageFile;
60 public ulong AvailPageFile;
61 public ulong TotalVirtual;
62 public ulong AvailVirtual;
63 public ulong AvailExtendedVirtual;
66 [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
67 [return: MarshalAs(UnmanagedType.Bool)]
68 internal static extern bool GlobalMemoryStatusEx(
69 ref NativeMethods.MemoryStatusEx buffer);