github.com/rentongzhang/docker@v1.8.2-rc1/pkg/system/meminfo_windows.go (about)

     1  package system
     2  
     3  import (
     4  	"syscall"
     5  	"unsafe"
     6  )
     7  
     8  var (
     9  	modkernel32 = syscall.NewLazyDLL("kernel32.dll")
    10  
    11  	procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx")
    12  )
    13  
    14  // https://msdn.microsoft.com/en-us/library/windows/desktop/aa366589(v=vs.85).aspx
    15  // https://msdn.microsoft.com/en-us/library/windows/desktop/aa366770(v=vs.85).aspx
    16  type memorystatusex struct {
    17  	dwLength                uint32
    18  	dwMemoryLoad            uint32
    19  	ullTotalPhys            uint64
    20  	ullAvailPhys            uint64
    21  	ullTotalPageFile        uint64
    22  	ullAvailPageFile        uint64
    23  	ullTotalVirtual         uint64
    24  	ullAvailVirtual         uint64
    25  	ullAvailExtendedVirtual uint64
    26  }
    27  
    28  // ReadMemInfo retrieves memory statistics of the host system and returns a
    29  //  MemInfo type.
    30  func ReadMemInfo() (*MemInfo, error) {
    31  	msi := &memorystatusex{
    32  		dwLength: 64,
    33  	}
    34  	r1, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(msi)))
    35  	if r1 == 0 {
    36  		return &MemInfo{}, nil
    37  	}
    38  	return &MemInfo{
    39  		MemTotal:  int64(msi.ullTotalPhys),
    40  		MemFree:   int64(msi.ullAvailPhys),
    41  		SwapTotal: int64(msi.ullTotalPageFile),
    42  		SwapFree:  int64(msi.ullAvailPageFile),
    43  	}, nil
    44  }