[英]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.