- SafeRegistryHandle.ReleaseHandle is only called on code that is ignored on Mono.
- Mono is using AppDomain.FriendlyName directly instead of UnsafeNativeMethods.GetModuleFileName.
[SecuritySafeCritical]
static MemoryMonitor() {
+#if MONO
+ var pc = new System.Diagnostics.PerformanceCounter ("Mono Memory", "Total Physical Memory");
+ s_totalPhysical = pc.RawValue;
+
+ // We should set the the total virtual memory with a system value.
+ // But Mono has no such PerformanceCounter and the total virtual memory has little relevance
+ // for the rest of the System.Runtime.Caching code.
+ s_totalVirtual = 0;
+#else
MEMORYSTATUSEX memoryStatusEx = new MEMORYSTATUSEX();
memoryStatusEx.Init();
if (UnsafeNativeMethods.GlobalMemoryStatusEx(ref memoryStatusEx) != 0) {
s_totalPhysical = memoryStatusEx.ullTotalPhys;
s_totalVirtual = memoryStatusEx.ullTotalVirtual;
}
+#endif
}
internal static long TotalPhysical { get { return s_totalPhysical; } }
// if the host has an identifier, use it
string appId = (ai != null) ? ai.GetApplicationId() : null;
// otherwise, use the process name wihtout file extension
+#if !MONO
if (String.IsNullOrEmpty(appId)) {
StringBuilder sb = new StringBuilder(512);
if (UnsafeNativeMethods.GetModuleFileName(IntPtr.Zero, sb, 512) != 0) {
appId = Path.GetFileNameWithoutExtension(sb.ToString());
}
}
+#endif
// if all else fails, use AppDomain.FriendlyName
if (String.IsNullOrEmpty(appId)) {
appId = AppDomain.CurrentDomain.FriendlyName;
[SecuritySafeCritical]
protected override int GetCurrentPressure() {
+#if MONO
+ var pc = new System.Diagnostics.PerformanceCounter ("Mono Memory", "Available Physical Memory");
+ long availableMemory = pc.RawValue;
+
+ int memoryLoad = (int) ((100 * availableMemory) / TotalPhysical);
+#else
MEMORYSTATUSEX memoryStatusEx = new MEMORYSTATUSEX();
memoryStatusEx.Init();
if (UnsafeNativeMethods.GlobalMemoryStatusEx(ref memoryStatusEx) == 0)
return 0;
int memoryLoad = memoryStatusEx.dwMemoryLoad;
+#endif
//if (_pressureHigh != 0) {
// PerfCounter: Cache Percentage Machine Memory Limit Used
// = total physical memory used / total physical memory used limit
[SecurityCritical]
protected override bool ReleaseHandle() {
// Returns a Win32 error code, 0 for success
+#if MONO
+ throw new NotImplementedException ();
+#else
int r = UnsafeNativeMethods.RegCloseKey(handle);
return r == 0;
+#endif
}
}
}