[英]java mapped FileChannel implementation
Reading a file in using a Mapped FileChannel
seems to be lightning fast... But I was wondering how they are doing this? 使用
Mapped FileChannel
读取文件似乎很快……但是我想知道他们是如何做到的?
Are they simply just reading in a large (~64kB) buffer and then letting me march through that? 他们只是在读一个大(〜64kB)的缓冲区,然后让我进入那个缓冲区吗? Or is there more to it?
还是还有更多呢?
I'm just impressed by the speed and want to better understand the algorithm behind it. 我对速度印象深刻,想更好地了解其背后的算法。
They don't read anything until you do, then the piece you read is basically read via the OS paging system. 他们只有在您读完之后才会阅读任何东西,然后您基本上可以通过OS分页系统阅读您所阅读的文章。 The open may cost you almost nothing but repeated reads of the same piece of the file may cause repeated I/O.
打开可能几乎不会花费您什么,但重复读取同一文件片段可能会导致重复的I / O。 Nothing is free.
没有什么是免费的。
memory mapping, maps the file into your memory and Java provides a library to to wrap this so you can access it relatively safely. 内存映射,将文件映射到您的内存中,并且Java提供了一个包装它的库,因此您可以相对安全地访问它。
It's benefits include: 它的好处包括:
It's disadvantages include: 它的缺点包括:
I have written a couple of libraries making memory mapped files easier to work with and I would say I would use it when ultra-low latency is critical or you need to read large amounts of memory which you expect to be in disk cache already and you want to make the most of your disk cache. 我已经编写了一些库,使内存映射文件更易于使用,我想说的是,当超低延迟非常关键,或者您需要读取大量的内存,而您希望这些内存已经存在于磁盘缓存中时,我会使用它。想要充分利用磁盘缓存。
It's worth noting that memory mapped doesn't make your disk sub-system faster and if that is your limiting factor it won't matter which way you read/write data. 值得注意的是,映射的内存并不能使您的磁盘子系统更快,如果这是您的限制因素,则用哪种方式读取/写入数据都无关紧要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.