mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-06-14 06:12:25 -06:00
Core: GetSystemMemoryStatus MacOSX
git-svn-id: svn://ultimatepp.org/upp/trunk@14572 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
bdff2b92b7
commit
576f8aeb7a
2 changed files with 35 additions and 8 deletions
|
|
@ -129,24 +129,29 @@ int CPU_Cores()
|
|||
|
||||
#endif
|
||||
|
||||
void GetSystemMemoryStatus(uint64& total, uint64& free)
|
||||
#ifdef PLATFORM_MACOS
|
||||
#include <mach/mach.h>
|
||||
#include <mach/vm_statistics.h>
|
||||
#endif
|
||||
|
||||
void GetSystemMemoryStatus(uint64& total, uint64& available)
|
||||
{
|
||||
#ifdef PLATFORM_WIN32
|
||||
MEMORYSTATUSEX m;
|
||||
m.dwLength = sizeof(m);
|
||||
if(GlobalMemoryStatusEx(&m)) {
|
||||
total = m.ullTotalPhys;
|
||||
free = m.ullAvailPhys;
|
||||
available = m.ullAvailPhys;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef PLATFORM_LINUX
|
||||
int pgsz = getpagesize();
|
||||
total = sysconf(_SC_PHYS_PAGES);
|
||||
free = sysconf(_SC_AVPHYS_PAGES);
|
||||
if(total >= 0 && free >= 0) {
|
||||
available = sysconf(_SC_AVPHYS_PAGES);
|
||||
if(total >= 0 && available >= 0) {
|
||||
total *= pgsz;
|
||||
free *= pgsz;
|
||||
available *= pgsz;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -160,13 +165,35 @@ void GetSystemMemoryStatus(uint64& total, uint64& free)
|
|||
|
||||
if(sysctlbyname("vm.vmtotal", &vmt, &vmt_size, NULL, 0) >= 0 &&
|
||||
sysctlbyname("vm.stats.vm.v_page_size", &page_size, &uint_size, NULL, 0) >= 0) {
|
||||
free = vmt.t_free * page_size;
|
||||
available = vmt.t_free * page_size;
|
||||
total = vmt.t_avm * page_size;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#ifdef PLATFORM_MACOS
|
||||
mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
|
||||
vm_statistics_data_t vmstat;
|
||||
|
||||
int mib[2];
|
||||
int64 physical_memory;
|
||||
size_t length;
|
||||
|
||||
// Get the Physical memory size
|
||||
mib[0] = CTL_HW;
|
||||
mib[1] = HW_MEMSIZE;
|
||||
length = sizeof(int64);
|
||||
|
||||
if(host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count) == KERN_SUCCESS &&
|
||||
sysctl(mib, 2, &physical_memory, &length, NULL, 0) >= 0) {
|
||||
int pgsz = getpagesize();
|
||||
available = (vmstat.free_count + vmstat.inactive_count) * pgsz;
|
||||
// available = physical_memory - (vmstat.wire_count + vmstat.inactive_count) * pgsz;
|
||||
total = physical_memory;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
total = 256*1024*1024;
|
||||
free = 16*1024*1024;
|
||||
available = 16*1024*1024;
|
||||
}
|
||||
|
||||
#define ENDIAN_SWAP { while(count--) { EndianSwap(*v++); } }
|
||||
|
|
|
|||
|
|
@ -484,7 +484,7 @@ bool CpuAVX();
|
|||
|
||||
int CPU_Cores();
|
||||
|
||||
void GetSystemMemoryStatus(uint64& total, uint64& free);
|
||||
void GetSystemMemoryStatus(uint64& total, uint64& available);
|
||||
|
||||
template <class T>
|
||||
inline void Swap(T& a, T& b) { T tmp = pick(a); a = pick(b); b = pick(tmp); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue