【问题标题】:Getting wrong available memory of ipad?获取错误的 ipad 可用内存?
【发布时间】:2012-06-22 11:17:03
【问题描述】:

我正在通过以下方法获取可用内存:

static void print_free_memory () {
float totalSpace = 0.0f;  
NSError *error = nil;  

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  

NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];  

if (dictionary) {  
    NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];  
    totalSpace = [fileSystemSizeInBytes floatValue];  
    NSLog(@"Total memory:%f",totalSpace);
    freeMemAvailable = [[dictionary objectForKey:NSFileSystemFreeSize] floatValue];
    NSLog(@"Free Memory:%f",freeMemAvailable);
} else {  
    NSLog(@"Error Obtaining File System Info: Domain = %@, Code = %@", [error domain], [error code]);  
}
}

上述方法返回 = 9139.650391 mb ~ 9.14 GB 与设备上显示的设备内存 = 8.4 GB

大约有 700 MB 的差异。为什么会这样?任何建议。

我在device上查看设备内存的路径如下。 转到:-设置->常规->关于->可用

【问题讨论】:

    标签: iphone xcode memory


    【解决方案1】:

    您的计算不精确,函数返回字节大小,因此假设返回值为9139650391,您需要将其除以(1024*1024*1024) = 1073741824

    所以9139650391/1073741824 大约等于 8.5 GB 而不是 9.14 GB

    大约100MB的差别,还是有差别的,但没有700MB那么大

    【讨论】:

    • 谢谢奥马尔。你说的对。我用 10^6 除。但仍然有约 100 MB 的差异。有什么想法吗?
    • 这 100 mb 我真的不知道,我会进一步调查
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多