Find total memory in use under OS X (XOP)
KevinRBoyce
So, here is what I use to find the total amount of the memory space in use, from within an XOP, on OS X.
<br />
/*<br />
Return the number of bytes allocated to our memory space.<br />
This should include all memory-mapped files and all shared memory.<br />
We need to know if we're running out of space for our 32-bit pointers.<br />
*/<br />
uint64_t memInUse()<br />
{<br />
kern_return_t kr;<br />
struct task_basic_info_64 ti;<br />
mach_msg_type_number_t count;<br />
<br />
count = TASK_BASIC_INFO_64_COUNT;<br />
kr = task_info( mach_task_self(), TASK_BASIC_INFO_64, (task_info_t)&ti, &count);<br />
<br />
return ti.virtual_size;<br />
}<br />
/*<br />
Return the number of bytes allocated to our memory space.<br />
This should include all memory-mapped files and all shared memory.<br />
We need to know if we're running out of space for our 32-bit pointers.<br />
*/<br />
uint64_t memInUse()<br />
{<br />
kern_return_t kr;<br />
struct task_basic_info_64 ti;<br />
mach_msg_type_number_t count;<br />
<br />
count = TASK_BASIC_INFO_64_COUNT;<br />
kr = task_info( mach_task_self(), TASK_BASIC_INFO_64, (task_info_t)&ti, &count);<br />
<br />
return ti.virtual_size;<br />
}<br />
For some reason, task_info() does not seem to have a manual entry in Mavericks, but you can read the description at http://www.gnu.org/software/hurd/gnumach-doc/Task-Information.html
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More