github.com/kayoticsully/syncthing@v0.8.9-0.20140724133906-c45a2fdc03f8/cmd/syncthing/memsize_windows.go (about)

     1  package main
     2  
     3  import (
     4  	"encoding/binary"
     5  	"syscall"
     6  	"unsafe"
     7  )
     8  
     9  var (
    10  	kernel32, _             = syscall.LoadLibrary("kernel32.dll")
    11  	globalMemoryStatusEx, _ = syscall.GetProcAddress(kernel32, "GlobalMemoryStatusEx")
    12  )
    13  
    14  func memorySize() (uint64, error) {
    15  	var memoryStatusEx [64]byte
    16  	binary.LittleEndian.PutUint32(memoryStatusEx[:], 64)
    17  	p := uintptr(unsafe.Pointer(&memoryStatusEx[0]))
    18  
    19  	ret, _, callErr := syscall.Syscall(uintptr(globalMemoryStatusEx), 1, p, 0, 0)
    20  	if ret == 0 {
    21  		return 0, callErr
    22  	}
    23  
    24  	return binary.LittleEndian.Uint64(memoryStatusEx[8:]), nil
    25  }