Find total memory in use under OS X (XOP)

I have had a need to make sure I'm not running out of memory while running an XOP on the Mac. Since we're still 32 bits over here in Mac-land, there is an absolute addressing limit of 4 GB, which includes memory-mapped files and system stuff. Under Mavericks, there seems to be about 1 GB used in an empty experiment. Since modern hardware can re-map blocks to make it always contiguous, that 4GB is the ultimate limit.

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 />

For some reason, task_info() does not seem to have a manual entry in Mavericks, but you can read the description at




Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More