public final class MemoryMappedFile extends NativeMemory
This class leverages the JVM Cleaner class that replaces Object.finalize()
and serves as a back-up if the calling class does not call freeMemory().
| Modifier and Type | Method and Description |
|---|---|
void |
force()
Forces any changes made to this content to be written to the storage device containing the
mapped file.
|
void |
freeMemory()
Because the Memory classes now use the JVM Cleaner, calling freeMemory(),
which also calls Cleaner, is optional.
|
static MemoryMappedFile |
getInstance(File file,
long position,
long len)
Factory method for creating a memory mapping a file.
|
boolean |
isLoaded()
Tells whether or not the content is resident in physical memory.
|
void |
load()
Loads content into physical memory.
|
addAndGetInt, addAndGetLong, array, asReadOnlyMemory, byteBuffer, clear, clear, clearBits, compareAndSwapInt, compareAndSwapLong, copy, copy, copy, fill, fill, getAddress, getAndSetInt, getAndSetLong, getBoolean, getBooleanArray, getByte, getByteArray, getCapacity, getChar, getCharArray, getCumulativeOffset, getDouble, getDoubleArray, getFloat, getFloatArray, getInt, getIntArray, getLong, getLongArray, getMemoryRequest, getParent, getShort, getShortArray, hasArray, hasByteBuffer, isAllBitsClear, isAllBitsSet, isAllocated, isAnyBitsClear, isAnyBitsSet, isDirect, isReadOnly, putBoolean, putBooleanArray, putByte, putByteArray, putChar, putCharArray, putDouble, putDoubleArray, putFloat, putFloatArray, putInt, putIntArray, putLong, putLongArray, putShort, putShortArray, setBits, setMemoryRequest, toHexString, wrappublic static MemoryMappedFile getInstance(File file, long position, long len) throws Exception
Memory maps a file directly in off heap leveraging native map0 method used in FileChannelImpl.c. The owner will have read write access to that address space.
file - File to be mappedposition - Memory map starting from this position in the filelen - Memory map at most len bytes > 0 starting from positionException - file not found or RuntimeException, etc.public void load()
public boolean isLoaded()
public void force()
If the file mapped into this buffer resides on a local storage device then when this method returns it is guaranteed that all changes made to the buffer since it was created, or since this method was last invoked, will have been written to that device.
If the file does not reside on a local device then no such guarantee is made.
If this buffer was not mapped in read/write mode (java.nio.channels.FileChannel.MapMode.READ_WRITE) then invoking this method has no effect.
public void freeMemory()
MemoryAllocMemory or MemoryMappedFile.
Preemptively calling freeMemory() may reduce the load on the JVM GarbageCollector, but the significance of this will have to be verified in the target system environment. Calling freeMemory() always disables the current instance by setting the capacity to zero.
freeMemory in interface MemoryfreeMemory in class NativeMemoryCopyright © 2015–2017 Yahoo! Inc.. All rights reserved.