nio - Java - memory mapped file benefits -


I am struggling to see the benefits of a memory map file (buffer) in Java. Here's how I look at the attitude in practice:

We take part in the main memory of the file and write any / write directly in the memory, leaving OS to work in keeping the disk in the file Give.

Now, I wanted to separate it with regular I / O and some scenarios:

  1. Attached in a file

In order to map the file to the memo, I have to read it in complete form so that the overall modifications can be completed. The size of the buffer size file is initially (assuming I do not know how much data I want to write in) Now, to add to the file, I can not do this because buffer is of limited size. So the most basic action seems impossible to me, apart from reading a complete file to add a small part, it seems useless. So I think regular I / O performs better in this scenario.

  1. Constant changes

I need to flush them to continue the changes. Therefore, if I do not do this from time to time then maybe I lost the change in main memory This is the same idea with regular I / O streams, so there is no benefit here.

  1. Random changes

This is where I can see it to work - instead of n bytes with other bytes. Despite this, it seems to be absolutely unusual operation that microns are exactly M. Characters to reflect. We will have Hello and replace it with Hello but we have a filled, fixed size buffer, so this is not easy ... Also, it will give me the RandomAccessFile with better performance.

Perhaps everything I wrote was nonsense, but I would be happy to do this, because it seems difficult and cumbersome (or impossible) for me to use a memory buffer.

One drawback is that you should Save time back to your memory-mapping disk Imagine that you are doing RAM for some very intense operational hours and suddenly one is black - all information is lost.


Comments