public class AllocMemory 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().
| Constructor and Description |
|---|
AllocMemory(long capacityBytes)
Constructor to allocate native memory.
|
AllocMemory(long capacityBytes,
MemoryRequest memReq)
Constructor for allocate native memory with MemoryRequest.
|
AllocMemory(NativeMemory origMem,
long copyToBytes,
long capacityBytes,
boolean clear,
MemoryRequest memReq)
Constructor to allocate new off-heap NativeMemory, copy from the given origMem,
and optionally clear the remainder.
|
AllocMemory(NativeMemory origMem,
long newCapacityBytes,
MemoryRequest memReq)
Constructor to allocate new off-heap native memory, copy the contents from the given origMem.
|
| Modifier and Type | Method and Description |
|---|---|
void |
freeMemory()
Because the Memory classes now use the JVM Cleaner, calling freeMemory(),
which also calls Cleaner, is optional.
|
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 AllocMemory(long capacityBytes)
Allocates and provides access to capacityBytes directly in native (off-heap) memory leveraging the Memory interface. The MemoryRequest callback is set to null. The allocated memory will be 8-byte aligned, but may not be page aligned.
capacityBytes - the size in bytes of the native memorypublic AllocMemory(long capacityBytes,
MemoryRequest memReq)
Allocates and provides access to capacityBytes directly in native (off-heap) memory leveraging the Memory interface. The allocated memory will be 8-byte aligned, but may not be page aligned.
capacityBytes - the size in bytes of the native memorymemReq - The MemoryRequest callbackpublic AllocMemory(NativeMemory origMem, long newCapacityBytes, MemoryRequest memReq)
Reallocates the given off-heap NativeMemory to a new a new native (off-heap) memory location and copies the contents of the original given NativeMemory to the new location. Any memory beyond the capacity of the original given NativeMemory will be uninitialized. The new allocated memory will be 8-byte aligned, but may not be page aligned.
origMem - The original NativeMemory that needs its contents to be reallocated.
It must not be null.newCapacityBytes - the desired new capacity of the newly allocated memory in bytesmemReq - The MemoryRequest callback, which may be null.public AllocMemory(NativeMemory origMem, long copyToBytes, long capacityBytes, boolean clear, MemoryRequest memReq)
Allocate a new native (off-heap) memory with capacityBytes; copy the contents of origMem from zero to copyToBytes; clear the new memory from copyToBytes to capacityBytes. The new allocated memory will be 8-byte aligned, but may not be page aligned.
origMem - The original Memory, a portion of which will be copied to the newly allocated
NativeMemory. The reference must not be null.
This origMem is not modified in any way, and may be reused .copyToBytes - the upper limit of the region to be copied from origMem to the newly
allocated memory, and the lower limit of the region to be cleared, if requested.capacityBytes - the desired new capacity of the newly allocated memory in bytes and the
upper limit of the region to be cleared.clear - if true the remaining region from copyToBytes to capacityBytes will be cleared.memReq - The MemoryRequest callback, which may be null.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.