memoryStatus retrieves information about the system's current usage of physical memory.
()
| 41 | // memoryStatus retrieves information about the system's current usage of |
| 42 | // physical memory. |
| 43 | func memoryStats() (*memory, error) { |
| 44 | mstat := struct { |
| 45 | size uint32 |
| 46 | _ uint32 |
| 47 | totalPhys uint64 |
| 48 | availPhys uint64 |
| 49 | _ [5]uint64 |
| 50 | }{} |
| 51 | |
| 52 | // windows sets return value to 0 when function fails. |
| 53 | mstat.size = uint32(unsafe.Sizeof(mstat)) |
| 54 | ret, _, err := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&mstat))) |
| 55 | if ret == 0 { |
| 56 | return nil, err |
| 57 | } |
| 58 | |
| 59 | // memoryStats functions from other platforms return memory usage in bytes. |
| 60 | return &memory{ |
| 61 | Usage: mstat.totalPhys - mstat.availPhys, |
| 62 | Total: mstat.totalPhys, |
| 63 | }, nil |
| 64 | |
| 65 | } |