Exemplo n.º 1
0
func (self *Mem) Get() error {
	var statex C.MEMORYSTATUSEX
	statex.dwLength = C.DWORD(unsafe.Sizeof(statex))

	succeeded := C.GlobalMemoryStatusEx(&statex)
	if succeeded == C.FALSE {
		lastError := C.GetLastError()
		return fmt.Errorf("GlobalMemoryStatusEx failed with error: %d", int(lastError))
	}

	self.Total = uint64(statex.ullTotalPhys)
	return nil
}
Exemplo n.º 2
0
func PhysmemAvail() uint64 {
	var msex C.MEMORYSTATUSEX
	msex.dwLength = C.DWORD(unsafe.Sizeof(msex))

	/* Preferable */
	if C.GlobalMemoryStatusEx(&msex) != C.FALSE {
		return uint64(msex.ullAvailPhys)
	}

	/* Fallback because it's incorrect over 4GB */
	var ms C.MEMORYSTATUS
	C.GlobalMemoryStatus(&ms)
	return uint64(ms.dwAvailPhys)
}
Exemplo n.º 3
0
func (self *Mem) Get() error {
	var statex C.MEMORYSTATUSEX
	statex.dwLength = C.DWORD(unsafe.Sizeof(statex))

	succeeded := C.GlobalMemoryStatusEx(&statex)
	if succeeded == C.FALSE {
		return syscall.GetLastError()
	}

	self.Total = uint64(statex.ullTotalPhys)
	self.Free = uint64(statex.ullAvailPhys)
	self.Used = self.Total - self.Free
	self.ActualFree = self.Free
	self.ActualUsed = self.Used

	return nil
}