Merge branch 'pre-master-47' into bt_dev

This commit is contained in:
Brian Taylor 2026-04-19 09:13:38 -07:00
commit e3b38040da
2 changed files with 24 additions and 21 deletions

View File

@ -65,26 +65,27 @@ unsigned long long getAvailableMemorySize(void)
#elif defined(__APPLE__) && defined(__MACH__)
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
#include <stdio.h>
#include <stdlib.h>
#include <sys/sysctl.h>
#include <mach/mach.h>
host_port = mach_host_self();
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
host_page_size(host_port, &pagesize);
mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
vm_statistics_data_t vm_stat;
vm_statistics64_data_t vmstats;
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t) &vm_stat,
&host_size) != KERN_SUCCESS) {
fprintf(stderr, "Failed to fetch vm statistics");
if (host_statistics64(mach_host_self(), HOST_VM_INFO64,
(host_info64_t)&vmstats, &count) == KERN_SUCCESS) {
// Calculate available memory (free + inactive)
const int page_size = PAGE_SIZE;
uint64_t free_memory = (uint64_t)vmstats.free_count * page_size;
uint64_t inactive_memory = (uint64_t)vmstats.inactive_count * page_size;
uint64_t available_memory = free_memory + inactive_memory;
return available_memory;
}
/* Stats in bytes */
/* natural_t mem_used = (vm_stat.active_count + vm_stat.inactive_count +
vm_stat.wire_count) * pagesize; */
return (unsigned long long)(vm_stat.free_count * pagesize);
// natural_t mem_total = mem_used + mem_free;
else
return 0;
#elif defined(__unix__) || defined(__unix) || defined(unix)
/* Linux/UNIX variants. ------------------------------------------- */

View File

@ -33,7 +33,6 @@
#error "Cannot define getPeakRSS( ) or getCurrentRSS( ) for an unknown OS."
#endif
/**
* Returns the peak (maximum so far) resident set size (physical
* memory use) measured in bytes, or zero if the value cannot be
@ -72,6 +71,13 @@ unsigned long long getPeakRSS(void)
GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) );
return (unsigned long long) info.PeakWorkingSetSize;
#elif defined(__APPLE__) && defined(__MACH__)
struct rusage rusage;
if (getrusage(RUSAGE_SELF, &rusage) == 0)
return (unsigned long long) rusage.ru_maxrss;
else
return 0L;
#elif (defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
/* AIX and Solaris ------------------------------------------ */
struct psinfo psinfo;
@ -92,10 +98,6 @@ unsigned long long getPeakRSS(void)
#endif
}
/**
* Returns the current resident set size (physical memory use) measured
* in bytes, or zero if the value cannot be determined on this OS.