最快的磁盘写入方式-iOS
我正在使用C函数,希望将数据持久化到磁盘。读写这些数据的最快方式是什么。我正在将最快的磁盘写入方式-iOS,ios,objective-c,c,Ios,Objective C,C,我正在使用C函数,希望将数据持久化到磁盘。读写这些数据的最快方式是什么。我正在将char*和intptr\t转换为NSString和NSNumber,将它们存储在字典中,然后将每个字典存储到NSMutableArray中。但是,是否有一种更快的方法来存储这些数据,而无需将值包装到Objective-C对象中 static void _print_image(const struct mach_header *mh, bool added) { Dl_info image_info;
char*
和intptr\t
转换为NSString
和NSNumber
,将它们存储在字典中,然后将每个字典存储到NSMutableArray
中。但是,是否有一种更快的方法来存储这些数据,而无需将值包装到Objective-C对象中
static void _print_image(const struct mach_header *mh, bool added)
{
Dl_info image_info;
int result = dladdr(mh, &image_info);
if (result == 0) {
printf("Could not print info for mach_header: %p\n\n", mh);
return;
}
const char *image_name = image_info.dli_fname;
const intptr_t image_base_address = (intptr_t)image_info.dli_fbase;
const char *log = added ? "Added" : "Removed";
//printf("%s: 0x%02lx %s\n\n", log, image_base_address, image_name);
NSString *imageName = [NSString stringWithUTF8String:image_name];
NSNumber *baseAddress = [NSNumber numberWithInteger:image_base_address];
NSDictionary *info = @{@"imageName" : imageName, @"baseAddress" : baseAddress};
[arr addObject:info];
}
这真的重要吗?这是系统中的性能瓶颈吗?我建议保持代码简单,只关注存在问题的优化/花哨代码。@Chris Well是的,它在我的应用程序启动时记录输出,因此我希望它对启动时间的影响尽可能小。是的,但有多少时间是I/O,有多少时间是CPU在Objective-C中进行类型转换?根据我的经验,几乎所有的时间都花在实际的I/O上。你还在尝试吗?祝您阅读和重用baseAddress好运。我很少看到有人被误导。