I'm trying to get the memory usage of the entire system.
// referance: https://www.jb51.cc/iOS/590624.html
public func memsize() -> UInt64 {
var taskInfo = mach_task_basic_info()
var count = UInt32(MemoryLayout<mach_task_basic_info>.size)
let kerr: kern_return_t = withUnsafeMutablePointer(to: &taskInfo) {
$0.withMemoryRebound(to: integer_t.self,capacity: 1) {
task_info(mach_task_self_,task_flavor_t(MACH_TASK_BASIC_INFO),$0,&count)
}
}
if kerr == KERN_SUCCESS {
return taskInfo.resident_size
}
return 0
}
not working, apparently. When my system uses 15 GB it shows it's below 1 GB.
Do anyone have other ways to get memory usage of the device (better macOS)