Reading a file in using a Mapped FileChannel
seems to be lightning fast... But I was wondering how they are doing this?
Are they simply just reading in a large (~64kB) buffer and then letting me march through that? Or is there more to it?
I'm just impressed by the speed and want to better understand the algorithm behind it.
memory mapping, maps the file into your memory and Java provides a library to to wrap this so you can access it relatively safely.
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.