Exemplo n.º 1
0
 static MemoryMonitor()
 {
     Interop.Kernel32.MEMORYSTATUSEX memoryStatusEx = default;
     memoryStatusEx.dwLength = (uint)Marshal.SizeOf <Interop.Kernel32.MEMORYSTATUSEX>();
     if (Interop.Kernel32.GlobalMemoryStatusEx(out memoryStatusEx) != 0)
     {
         s_totalPhysical = (long)memoryStatusEx.ullTotalPhys;
         s_totalVirtual  = (long)memoryStatusEx.ullTotalVirtual;
     }
 }
#pragma warning disable CA1810 // explicit static cctor
        static unsafe MemoryMonitor()
        {
            Interop.Kernel32.MEMORYSTATUSEX memoryStatus = default;
            memoryStatus.dwLength = (uint)sizeof(Interop.Kernel32.MEMORYSTATUSEX);
            if (Interop.Kernel32.GlobalMemoryStatusEx(ref memoryStatus))
            {
                s_totalPhysical = (long)memoryStatus.ullTotalPhys;
                s_totalVirtual  = (long)memoryStatus.ullTotalVirtual;
            }
        }
Exemplo n.º 3
0
 public static unsafe void CheckForAvailableVirtualMemory(ulong nativeSize)
 {
     Interop.Kernel32.MEMORYSTATUSEX memoryStatus = default;
     memoryStatus.dwLength = (uint)sizeof(Interop.Kernel32.MEMORYSTATUSEX);
     if (Interop.Kernel32.GlobalMemoryStatusEx(ref memoryStatus))
     {
         ulong totalVirtual = memoryStatus.ullTotalVirtual;
         if (nativeSize >= totalVirtual)
         {
             throw new IOException(SR.IO_NotEnoughMemory);
         }
     }
 }
Exemplo n.º 4
0
        protected override unsafe int GetCurrentPressure()
        {
            Interop.Kernel32.MEMORYSTATUSEX memoryStatus = default;
            memoryStatus.dwLength = (uint)sizeof(Interop.Kernel32.MEMORYSTATUSEX);
            if (Interop.Kernel32.GlobalMemoryStatusEx(&memoryStatus) == Interop.BOOL.FALSE)
            {
                return(0);
            }

            int memoryLoad = (int)memoryStatus.dwMemoryLoad;

            return(memoryLoad);
        }
        protected override int GetCurrentPressure()
        {
            Interop.Kernel32.MEMORYSTATUSEX memoryStatusEx = default;
            memoryStatusEx.dwLength = (uint)Marshal.SizeOf(typeof(Interop.Kernel32.MEMORYSTATUSEX));
            if (Interop.Kernel32.GlobalMemoryStatusEx(out memoryStatusEx) == 0)
            {
                return(0);
            }

            int memoryLoad = (int)memoryStatusEx.dwMemoryLoad;

            return(memoryLoad);
        }
Exemplo n.º 6
0
        private static void CheckForAvailableMemory(out ulong availPageFile, out ulong totalAddressSpaceFree)
        {
            bool r;

            Interop.Kernel32.MEMORYSTATUSEX memory = new Interop.Kernel32.MEMORYSTATUSEX();
            r = Interop.Kernel32.GlobalMemoryStatusEx(ref memory);
            if (!r)
            {
                throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error());
            }
            availPageFile         = memory.availPageFile;
            totalAddressSpaceFree = memory.availVirtual;
        }
Exemplo n.º 7
0
        private static void CheckForAvailableMemory(out ulong availPageFile, out ulong totalAddressSpaceFree)
        {
            bool r;

            Interop.Kernel32.MEMORYSTATUSEX memory = new Interop.Kernel32.MEMORYSTATUSEX();
            r = Interop.Kernel32.GlobalMemoryStatusEx(ref memory);
            if (!r)
            {
                throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error());
            }
            availPageFile         = memory.availPageFile;
            totalAddressSpaceFree = memory.availVirtual;
            // Console.WriteLine($"Memory gate:  Mem load: {memory.memoryLoad}%  Available memory (physical + page file): {(memory.availPageFile >> 20)} MB  Total free address space: {memory.availVirtual >> 20} MB  GC Heap: {(GC.GetTotalMemory(true) >> 20)} MB");
        }
Exemplo n.º 8
0
 private static unsafe bool CheckForAvailableMemory(out ulong availPageFile, out ulong totalAddressSpaceFree)
 {
     Interop.Kernel32.MEMORYSTATUSEX memoryStatus = default;
     memoryStatus.dwLength = (uint)sizeof(Interop.Kernel32.MEMORYSTATUSEX);
     if (!Interop.Kernel32.GlobalMemoryStatusEx(ref memoryStatus))
     {
         availPageFile         = default;
         totalAddressSpaceFree = default;
         return(false);
     }
     availPageFile         = memoryStatus.ullAvailPageFile;
     totalAddressSpaceFree = memoryStatus.ullAvailVirtual;
     // Console.WriteLine($"Memory gate:  Mem load: {memory.memoryLoad}%  Available memory (physical + page file): {(memory.availPageFile >> 20)} MB  Total free address space: {memory.availVirtual >> 20} MB  GC Heap: {(GC.GetTotalMemory(true) >> 20)} MB");
     return(true);
 }