cocoaTouch/otherSrc/CommodityFunctions.m
changeset 3490 016b3172b645
parent 3479 972ae3ec178a
child 3495 a6b4f351d400
equal deleted inserted replaced
3489:aedf289192f5 3490:016b3172b645
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
     7 //
     7 //
     8 
     8 
     9 #import "CommodityFunctions.h"
     9 #import "CommodityFunctions.h"
    10 #import "SDL_uikitappdelegate.h"
    10 #import "SDL_uikitappdelegate.h"
       
    11 #import <mach/mach.h>
       
    12 #import <mach/mach_host.h>
    11 
    13 
    12 void createTeamNamed (NSString *nameWithoutExt) {
    14 void createTeamNamed (NSString *nameWithoutExt) {
    13     NSString *teamsDirectory = TEAMS_DIRECTORY();
    15     NSString *teamsDirectory = TEAMS_DIRECTORY();
    14     
    16     
    15     if (![[NSFileManager defaultManager] fileExistsAtPath: teamsDirectory]) {
    17     if (![[NSFileManager defaultManager] fileExistsAtPath: teamsDirectory]) {
   108                                           cancelButtonTitle:@"Ok"
   110                                           cancelButtonTitle:@"Ok"
   109                                           otherButtonTitles:nil];
   111                                           otherButtonTitles:nil];
   110     [alert show];
   112     [alert show];
   111     [alert release];
   113     [alert release];
   112 }
   114 }
       
   115 
       
   116 // by http://landonf.bikemonkey.org/code/iphone/Determining_Available_Memory.20081203.html
       
   117 void print_free_memory () {
       
   118     mach_port_t host_port;
       
   119     mach_msg_type_number_t host_size;
       
   120     vm_size_t pagesize;
   113     
   121     
   114 
   122     host_port = mach_host_self();
   115 
   123     host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
       
   124     host_page_size(host_port, &pagesize);        
       
   125  
       
   126     vm_statistics_data_t vm_stat;
       
   127               
       
   128     if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS)
       
   129         DLog(@"Failed to fetch vm statistics");
       
   130  
       
   131     /* Stats in bytes */ 
       
   132     natural_t mem_used = (vm_stat.active_count +
       
   133                           vm_stat.inactive_count +
       
   134                           vm_stat.wire_count) * pagesize;
       
   135     natural_t mem_free = vm_stat.free_count * pagesize;
       
   136     natural_t mem_total = mem_used + mem_free;
       
   137     DLog(@"used: %u free: %u total: %u", mem_used, mem_free, mem_total);
       
   138 }