Interface MemoryRequestServer

All Known Implementing Classes:
DefaultMemoryRequestServer

public interface MemoryRequestServer
MemoryRequestServer relies on preview features of the Java platform:
  • MemoryRequestServer refers to one or more preview APIs: Arena.
Programs can only use MemoryRequestServer when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
The MemoryRequestServer is a callback interface to provide a means to request more memory for heap and off-heap WritableMemory resources that are not file-memory-mapped backed resources.

Note: this only works with Java 21.

Author:
Lee Rhodes
  • Method Details

    • request

      default WritableMemory request(WritableMemory currentWritableMemory, long newCapacityBytes)
      Request new WritableMemory with the given newCapacityBytes. The current WritableMemory can be used to determine the byte order of the returned WritableMemory and other properties. A new confined Arena is assigned.
      Parameters:
      currentWritableMemory - the current writableMemory of the client. It must be non-null.
      newCapacityBytes - The capacity being requested. It must be > the capacity of the currentWritableMemory.
      Returns:
      new WritableMemory with the requested capacity.
    • request

      WritableMemory request(WritableMemory currentWritableMemory, long newCapacityBytes, ArenaPREVIEW arena)
      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.
      Parameters:
      currentWritableMemory - 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

      default void requestClose(WritableMemory memToClose)
      Request to close the resource, if applicable.
      Parameters:
      memToClose - the relevant WritableMemory to be considered for closing. It must be non-null.
    • requestClose

      void requestClose(WritableMemory memToClose, WritableMemory newMemory)
      Request to close the resource, if applicable.
      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.