github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/memory/memory_darwin.go (about) 1 package memory 2 3 // #include <mach/mach.h> 4 import "C" 5 import "unsafe" 6 7 const nativeAvailable = true 8 9 func usageNative() uint64 { 10 var memoryUsageInByte uint64 11 var vmInfo C.task_vm_info_data_t 12 var count C.mach_msg_type_number_t = C.TASK_VM_INFO_COUNT 13 var kernelReturn C.kern_return_t = C.task_info(C.vm_map_t(C.mach_task_self_), C.TASK_VM_INFO, (*C.integer_t)(unsafe.Pointer(&vmInfo)), &count) 14 if kernelReturn == C.KERN_SUCCESS { 15 memoryUsageInByte = uint64(vmInfo.phys_footprint) 16 } 17 return memoryUsageInByte 18 }