简体   繁体   English

为大型文件和小型文件创建NSFileHandle之间有性能差异吗?

[英]Is there any performance difference between creating an NSFileHandle for a large versus a small file?

This question strikes me as almost silly, but I just want to sanity check myself. 这个问题使我感到几乎是愚蠢的,但我只是想理智地检查自己。 For a variety of reasons, I'm welding together a bunch of files into a single megafile before packing this as a resource in my iOS app. 由于各种原因,在将其打包为iOS应用程序中的资源之前,我将一堆文件焊接成一个大文件。 I'm then using NSFileHandle to open the file, seek to the right place, and read out just the bytes I want. 然后,我使用NSFileHandle打开文件,查找到正确的位置,然后仅读出所需的字节。

Is there any performance difference between doing it this way and reading loose files? 通过这种方式执行的操作与读取松散的文件之间是否存在性能差异? Or, supposing I could choose to use just one monolithic megafile, versus, say, 10 medium-sized (but still joined) files, is there any performance difference between "opening" the large versus a smaller file? 或者,假设我可以选择仅使用一个整体式大型文件,而不是使用10个中型(但仍加入)文件,那么“打开”大型文件与较小文件之间是否有性能差异?

Since I know exactly where to seek to, and I'm reading just the bytes I want, I don't see how there could be a difference. 由于我确切地知道要寻找的位置,并且我只读取想要的字节,因此我看不出会有什么不同。 But, hey -- Stranger things have proved to be. 但是,嘿-陌生人的事情已经证明是。 Thanks in advance! 提前致谢!

There could be a difference if it was an extremely large number of files. 如果文件数量过多,可能会有所不同。 Every open file uses up resources in memory (file handles, and the like), and on some storage devices, a file will take up an entire block even if it doesn't fill it. 每个打开的文件都会占用内存中的资源(文件句柄等),在某些存储设备上,即使文件没有填满,它也会占用整个块。 That can lead to wasted space in extreme cases. 在极端情况下,这可能会导致空间浪费。 But in practice, it probably won't be a problem. 但是实际上,这可能不会成为问题。 To know for sure, you can profile your code and see if it's faster one way vs. the other, and see what sort of space it takes up on a typical device. 可以肯定地说,您可以对代码进行概要分析,以查看一种方法相对于另一种方法是否更快,并查看典型设备占用哪种空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS:NSFileHandle与NSOutputStream进行大文件下载 - iOS: NSFileHandle vs NSOutputStream for large file download 使用NSFileHandle创建文件后清空文档目录 - Empty documents directory after creating file with NSFileHandle 下载大文件时应用崩溃-NSFileHandle seekToEndOfFile - App crashing when downloading a large file - NSFileHandle seekToEndOfFile Objective-C中点符号与方法调用之间的性能差异 - Performance difference between dot notation versus method call in Objective-C 使用NSFileHandle发送大量数据 - Sending large amounts of data with NSFileHandle 单个对象上的removeObject与removeObjectAtIndex之间是否有性能差异? - Any performance difference between removeObject vs removeObjectAtIndex on a single object? 使用NSFileHandle进行文件读/写的示例 - Example for file read/write with NSFileHandle NSFileHandle和编写Asynch到iOS中的文件 - NSFileHandle & Writing Asynch to a file in iOS 在实现和接口文件中创建UIViewController实例有什么区别? - What is the difference between creating UIViewController instance in implmentation and interface file? 在扩展接口中声明成员与在实现中声明成员之间有什么区别? - What is the difference between declaring a member in the extended interface versus in the implementation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM