From d483d620b69102a48829deb9f0d4a7f89213b9a5 Mon Sep 17 00:00:00 2001 From: karelrooted Date: Sat, 16 Dec 2023 14:33:44 +0800 Subject: [PATCH] Fix system memory size of tvOS use sysctlbyname("hw.memsize") to get sytem memory size instead of host_info, host_info is not available on tvOS, so we change to sysctlbyname which support all apple platforms apple document didn't stat this API is available on tvOS though, https://developer.apple.com/documentation/kernel/1387446-sysctlbyname --- Common/MVKOSExtensions.mm | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Common/MVKOSExtensions.mm b/Common/MVKOSExtensions.mm index 8d33f3d4..df2392ab 100644 --- a/Common/MVKOSExtensions.mm +++ b/Common/MVKOSExtensions.mm @@ -23,6 +23,7 @@ #include #include #include +#include #import @@ -100,17 +101,12 @@ double mvkGetEnvVarNumber(const char* varName, double defaultValue) { #pragma mark System memory uint64_t mvkGetSystemMemorySize() { -#if MVK_MACOS_OR_IOS_OR_VISIONOS - mach_msg_type_number_t host_size = HOST_BASIC_INFO_COUNT; - host_basic_info_data_t info; - if (host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&info, &host_size) == KERN_SUCCESS) { - return info.max_mem; + uint64_t host_memsize = 0; + size_t size = sizeof(host_memsize); + if (sysctlbyname("hw.memsize", &host_memsize, &size, NULL, 0) == KERN_SUCCESS) { + return host_memsize; } return 0; -#endif -#if MVK_TVOS - return 0; -#endif } uint64_t mvkGetAvailableMemorySize() {