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(@"");
    
}

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。