mac内存结构

相信大家做iphone开发都遇到过内存吃紧的问题,最要命的是不知道究竟自己刚写的这段代码用了多少内存(被instrument骗过好多次了),下面贴出我常用的查看现有内存方法

代码
- (double)availableMemory {
    vm_statistics_data_t vmStats;
    mach_msg_type_number_t infoCount 
= HOST_VM_INFO_COUNT;
    kern_return_t kernReturn 
= host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);
    
    
if(kernReturn != KERN_SUCCESS) {
        
return NSNotFound;
    }
    
//vmStats.wire_count
    
//vmStats.inactive_count
    
//vmStats.active_count
    return ((vm_page_size * vmStats.free_count) / 1024.0/ 1024.0;
}

 

以下是相关内存用语的名词解释 

 

Free memory

This is RAM that's not being used.
 

Wired memory

Information in this memory can't be moved to the hard disk, so it must stay in RAM. The amount of Wired memory depends on the applications you are using.
 

Active memory

This information is currently in memory, and has been recently used.
 

Inactive memory

This information in memory is not actively being used, but was recently used.

For example, if you've been using Mail and then quit it, the RAM that Mail was using is marked as Inactive memory. This Inactive memory is available for use by another application, just like Free memory.  However, if you open Mail before its Inactive memory is used by a different application, Mail will open quicker because its Inactive memory is converted to Active memory, instead of loading Mail from the slower hard disk.
 

Used

This is the total amount of memory used.
 

VM size

This is the total amount of Virtual Memory for all processes on your Mac. 
 

Page ins / Page outs

This refers to the amount of information moved between RAM and the hard disk. This number is a cumulative amount of data that Mac OS X has moved between RAM and disk space.

Tip: Page outs occur when your Mac has to write information from RAM to the hard drive (because RAM is full).  Adding more RAM may reduce page outs.
 

Swap used

This is the amount of information copied to the swap file on your hard drive.


(更多内存使用信息可查阅苹果开发文档:Memory Usage Performance Guidelines )

 

 

 

posted @ 2011-01-28 10:55  tony508  阅读(595)  评论(0)    收藏  举报