テキトーっす
#import <Foundation/Foundation.h>
@interface F8VmStatistics : NSObject
@property (nonatomic, readonly) NSInteger freeSize;
@property (nonatomic, readonly) NSInteger activeSize;
@property (nonatomic, readonly) NSInteger inactiveSize;
@end
#import "F8VmStatistics.h"
#import <mach/mach.h>
#import <mach/mach_host.h>
@implementation F8VmStatistics {
vm_statistics_data_t data_;
vm_size_t pagesize_;
}
#pragma mark - Public ( Readonly Properties )
- (NSInteger)freeSize {
return data_.free_count * pagesize_;
}
- (NSInteger)activeSize {
return data_.free_count * pagesize_;
}
- (NSInteger)inactiveSize {
return data_.inactive_count * pagesize_;
}
#pragma mark - Public ( Override NSObject )
- (id)init {
self = [super init];
if ( self ) {
mach_port_t host_port = mach_host_self();
mach_msg_type_number_t host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
host_page_size(host_port, &pagesize_);
if (host_statistics(host_port,
HOST_VM_INFO,
(host_info_t)&data_,
&host_size)
!= KERN_SUCCESS) {
NSLog(@"Failed to fetch vm statistics");
}
}
return self;
}
@end