首页 > 代码库 > ios plist文件和加载到内存时占用空间大小

ios plist文件和加载到内存时占用空间大小

plist文件以文本形式存储,一个字符占用一个字节,外加plist文件的头部,占用空间就是所有的字符数。

加载到内存所占空间与文件大小一致。

比如下方一个字符串是300个字符。10000个对象存储到文件中,文件大小为3.2MB。加载到内存所占空间也是3.2MB

- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.    NSMutableArray *array = [[NSMutableArray alloc] init];        for (int i=0; i<10000; i++) {        [array addObject:@"adsjadslkjfksdajfklasjdkfkalsdklfadsjadslkjfksdajfklasjdkfkalsdklfadsjadslkjfksdajfklasjdkfkalsdklfadsjadslkjfksdajfklasjdkfkalsdklfadsjadslkjfksdajfklasjdkfkalsdklfadsjadslkjfksdajfklasjdkfkalsdklfadsjadslkjfksdajfklasjdkfkalsdklfadsjadslkjfksdajfklasjdkfkalsdklfadsjadslkjfksdajfklasjdkfkalsdklfa300"];    }    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);    NSString *documentsDirectory = [paths objectAtIndex:0];    NSString *fileName = @"1.plist";    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:fileName];    NSLog(@"path is : %@",filePath);    [array writeToFile:filePath atomically:YES];        NSArray *arr2 = [NSArray arrayWithContentsOfFile:filePath];    self.arr2 = arr2;    NSLog(@"");    }

 

ios plist文件和加载到内存时占用空间大小