Skip to content

Instantly share code, notes, and snippets.

@chamons
Created June 30, 2015 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chamons/9811ed1505e2220cf124 to your computer and use it in GitHub Desktop.
Save chamons/9811ed1505e2220cf124 to your computer and use it in GitHub Desktop.
//
// AppDelegate.m
// DirGetNative
//
// Created by Chris Hamons on 6/30/15.
// Copyright (c) 2015 Chris Hamons. All rights reserved.
//
#import "AppDelegate.h"
#import <mach/mach.h>
@import Foundation;
// http://stackoverflow.com/questions/787160/programmatically-retrieve-memory-usage-on-iphone
void report_memory(void) {
struct task_basic_info info;
mach_msg_type_number_t size = sizeof(info);
kern_return_t kerr = task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t)&info,
&size);
if( kerr == KERN_SUCCESS ) {
NSLog(@"Memory in use (in bytes): %u", info.resident_size);
} else {
NSLog(@"Error with task_info(): %s", mach_error_string(kerr));
}
}
@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *window;
@end
NSButton *b;
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
b = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 200, 100)];
[[_window contentView] addSubview:b];
b.target = self;
b.action = @selector(onButtonPress);
}
- (void) onButtonPress {
b.enabled = NO;
NSFileManager * fm = [NSFileManager defaultManager];
NSString * o = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, true)[0];
NSString * path = [o stringByAppendingString:@"/TestFiles/"];
NSDirectoryEnumerator * e = [fm enumeratorAtPath:path];
int counter = 0;
while (true)
{
NSObject * file = [e nextObject];
if (file == nil)
break;
counter++;
}
NSLog (@"%d", counter);
report_memory ();
b.enabled = YES;
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment