[videodb] remove unused seasons table from episode_view
[xbmc.git] / xbmc / platform / darwin / MemUtils.cpp
blob4170ded8e3e30e17ddfae5f3410df68ad320495a
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "utils/MemUtils.h"
11 #include <array>
12 #include <cstdlib>
13 #include <cstring>
14 #include <stdio.h>
16 #include <mach/mach.h>
17 #include <sys/sysctl.h>
18 #include <sys/types.h>
19 #include <unistd.h>
21 namespace KODI
23 namespace MEMORY
26 void* AlignedMalloc(size_t s, size_t alignTo)
28 void* p;
29 posix_memalign(&p, alignTo, s);
31 return p;
34 void AlignedFree(void* p)
36 free(p);
39 void GetMemoryStatus(MemoryStatus* buffer)
41 if (!buffer)
42 return;
44 uint64_t physmem;
45 size_t len = sizeof physmem;
47 #if defined(__apple_build_version__) && __apple_build_version__ < 10000000
48 #pragma clang diagnostic push
49 #pragma clang diagnostic ignored "-Wmissing-braces"
50 #endif
51 std::array<int, 2> mib =
53 CTL_HW,
54 HW_MEMSIZE,
56 #if defined(__apple_build_version__) && __apple_build_version__ < 10000000
57 #pragma clang diagnostic pop
58 #endif
60 // Total physical memory.
61 if (sysctl(mib.data(), mib.size(), &physmem, &len, nullptr, 0) == 0 && len == sizeof(physmem))
62 buffer->totalPhys = physmem;
64 // In use.
65 mach_port_t stat_port = mach_host_self();
66 vm_statistics_data_t vm_stat;
67 mach_msg_type_number_t count = sizeof(vm_stat) / sizeof(natural_t);
68 if (host_statistics(stat_port, HOST_VM_INFO, reinterpret_cast<host_info_t>(&vm_stat), &count) == 0)
70 // Find page size.
71 #if defined(TARGET_DARWIN_IOS)
72 // on ios with 64bit ARM CPU the page size is wrongly given as 16K
73 // when using the sysctl approach. We can use the host_page_size
74 // function instead which will give the proper 4k pagesize
75 // on both 32 and 64 bit ARM CPUs
76 vm_size_t pageSize;
77 host_page_size(stat_port, &pageSize);
78 #else
79 int pageSize;
80 mib[0] = CTL_HW;
81 mib[1] = HW_PAGESIZE;
82 len = sizeof(int);
83 if (sysctl(mib.data(), mib.size(), &pageSize, &len, nullptr, 0) == 0)
84 #endif
86 uint64_t used = (vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count) * pageSize;
87 buffer->availPhys = buffer->totalPhys - used;