File tree 1 file changed +22
-3
lines changed
1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change 5
5
#include " sys/sysinfo.h"
6
6
#include < unistd.h>
7
7
#elif __APPLE__
8
- // #include mac hdr
8
+ #include < mach/vm_statistics.h>
9
+ #include < mach/mach_types.h>
10
+ #include < mach/mach_init.h>
11
+ #include < mach/mach_host.h>
9
12
#endif
10
13
11
14
// [[Rcpp::export(name = ".availableRAM")]]
@@ -21,9 +24,25 @@ double availableRAM(double ram) {
21
24
sysinfo (&memInfo);
22
25
ram = memInfo.freeram ;
23
26
#else
27
+ vm_size_t page_size;
28
+ mach_port_t mach_port;
29
+ mach_msg_type_number_t count;
30
+ vm_statistics64_data_t vm_stats;
31
+
32
+ mach_port = mach_host_self ();
33
+ count = sizeof (vm_stats) / sizeof (natural_t );
34
+ if (KERN_SUCCESS == host_page_size (mach_port, &page_size) &&
35
+ KERN_SUCCESS == host_statistics64 (mach_port, HOST_VM_INFO,
36
+ (host_info64_t )&vm_stats, &count)) {
37
+ long long free_memory = (int64_t )vm_stats.free_count * (int64_t )page_size;
38
+
39
+ // long long used_memory = ((int64_t)vm_stats.active_count +
40
+ // (int64_t)vm_stats.inactive_count +
41
+ // (int64_t)vm_stats.wire_count) * (int64_t)page_size;
42
+ ram = free_memory;
43
+ }
24
44
// mac
25
- // perhaps use this
26
- // https://stackoverflow.com/questions/38490320/how-to-query-amount-of-allocated-memory-on-linux-and-osx
45
+ // https://stackoverflow.com/questions/63166/how-to-determine-cpu-and-memory-consumption-from-inside-a-process
27
46
#endif
28
47
29
48
return ram;
You can’t perform that action at this time.
0 commit comments