Package org.apache.datasketches.memory
Class DefaultMemoryRequestServer
java.lang.Object
org.apache.datasketches.memory.DefaultMemoryRequestServer
- All Implemented Interfaces:
MemoryRequestServer
DefaultMemoryRequestServer
relies on preview features of the Java platform:
DefaultMemoryRequestServer
refers to one or more preview APIs:Arena
.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
This example MemoryRequestServer is simple but demonstrates one of many ways to
manage continuous requests for larger memory.
This capability is only available for writable, non-file-memory-mapping resources.
- Author:
- Lee Rhodes
-
Constructor Summary
ConstructorDescriptionDefault constructor.DefaultMemoryRequestServer
(boolean offHeap, boolean copyOldToNew) Constructor with parameters -
Method Summary
Modifier and TypeMethodDescriptionrequest
(WritableMemory currentWmem, long newCapacityBytes, ArenaPREVIEW arena) Request new WritableMemory with the given newCapacityBytes.void
requestClose
(WritableMemory memToClose, WritableMemory newMemory) Request to close the resource, if applicable.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.datasketches.memory.MemoryRequestServer
request, requestClose
-
Constructor Details
-
DefaultMemoryRequestServer
public DefaultMemoryRequestServer()Default constructor. Create new memory on-heap and do not copy old contents to new memory. -
DefaultMemoryRequestServer
public DefaultMemoryRequestServer(boolean offHeap, boolean copyOldToNew) Constructor with parameters- Parameters:
offHeap
- if true, the returned new memory will be off heapcopyOldToNew
- if true, the data from the current memory will be copied to the new memory, starting at address 0, and through the currentMemory capacity.
-
-
Method Details
-
request
public WritableMemory request(WritableMemory currentWmem, long newCapacityBytes, ArenaPREVIEW arena) Description copied from interface:MemoryRequestServer
Request new WritableMemory with the given newCapacityBytes. The current Writable Memory can be used to determine the byte order of the returned WritableMemory and other properties.- Specified by:
request
in interfaceMemoryRequestServer
- Parameters:
currentWmem
- the current writableMemory of the client. It must be non-null.newCapacityBytes
- The capacity being requested. It must be > the capacity of the currentWritableMemory.arena
- the Arena to be used for the newly allocated memory. It must be non-null. Warning: This class is not thread-safe. Specifying an Arena that allows multiple threads is not recommended.- Returns:
- new WritableMemory with the requested capacity.
-
requestClose
Description copied from interface:MemoryRequestServer
Request to close the resource, if applicable.- Specified by:
requestClose
in interfaceMemoryRequestServer
- Parameters:
memToClose
- the relevant WritableMemory to be considered for closing. It must be non-null.newMemory
- the newly allocated WritableMemory. The newMemory reference is returned from the client for the convenience of the system that owns the responsibility of memory allocation. It may be null.
-
DefaultMemoryRequestServer
when preview features are enabled.