It seems to me that MappedByteBuffer.isLoaded () returns consistently falseon Windows. When I test BSD Unix, I get trueusing the same test data.
Should I worry? I basically cannot get isLoaded()to return true on Windows, no matter what size data I use.
Here is my test code for reference:
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.logging.Level;
import java.util.logging.Logger;
public class MemMapTest {
private static final String FILENAME = "mydata.dat";
private static final int MB_1 = 1048576;
private static final byte[] testData = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
public static void main(String[] args) throws FileNotFoundException, IOException {
RandomAccessFile testFile = new RandomAccessFile(FILENAME, "rw");
for (int i = 0; i < MB_1; i++) {
testFile.write(testData);
}
MappedByteBuffer mapbuf = testFile.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, MB_1 * 20).load();
testFile.close();
if (mapbuf.isLoaded()) {
System.out.println("File is loaded in memory");
} else {
System.out.println("File is NOT loaded in memory");
}
}
}
I understand that load()- this is just a hint, but with such small sizes as I use here, I would expect it to isLoaded()return true at some point. As already mentioned, this is due to the Windows OS. This basically means that it is isLoaded()completely useless.
, , MappedByteBuffer Windows , isLoaded() false. , , .
Windows 7, Oracle Java 7 9.