title: How to find memory usage in mac OSX?
body: <p>How to find memory usage like an activity monitor display in osx 10.9 and above.
  i have used following code to fetch memory usage.</p>
  
  <p>but there is some difference between what it shows in activity monitor and what is i find by this code.</p>
  
  <pre><code>mach_port_t host_port;
  mach_msg_type_number_t host_size;
  vm_size_t pagesize;
  host_port = mach_host_self();
  host_size = sizeof(vm_statistics64_data_t) / sizeof(integer_t);
  host_page_size(host_port, &amp;pagesize);
  vm_statistics_data_t vm_stat;
  if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&amp;vm_stat, &amp;host_size) != KERN_SUCCESS)
  {
      NSLog(@"Failed to fetch vm statistics");
  }
  float free_count = vm_stat.free_count * pagesize;
  
  float active_count=vm_stat.active_count *pagesize;
  
  float inactive_count=vm_stat.inactive_count * pagesize;
  
  float wire_used=vm_stat.wire_count *pagesize;
  
  float zero_fill_count=vm_stat.zero_fill_count * pagesize;
  
  float reactivations=vm_stat.reactivations *pagesize;
  
  float pageins=vm_stat.pageins *pagesize;
  
  float pageouts=vm_stat.pageouts *pagesize;
  
  float faults=vm_stat.faults *pagesize;
  
  float cow_faults=vm_stat.cow_faults * pagesize;
  
  float lookups=vm_stat.lookups *pagesize;
  
  float hits=vm_stat.hits * pagesize;
  
  float purgeable_count=vm_stat.purgeable_count * pagesize;
  
  float purges=vm_stat.purges *pagesize;
  
  float speculative_count=vm_stat.speculative_count *pagesize;
  </code></pre>
  
  <p>I am also wondering that which should i consider as App memory, File caches, wired memory and compressed memory.</p>
  
  <p>Here, wired count i got using this code is same as displaying in an activity monitor.</p>
  
  <p>Can some one help me out here. Thanks</p>