Class DefaultMemoryRequestServer

java.lang.Object
org.apache.datasketches.memory.DefaultMemoryRequestServer
All Implemented Interfaces:
MemoryRequestServer

public final class DefaultMemoryRequestServer extends Object implements MemoryRequestServer
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 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 heap
      copyOldToNew - 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, ResourceScope scope)
      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 interface MemoryRequestServer
      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.
      scope - the ResourceScope to be used for the newly allocated memory.
      Returns:
      new WritableMemory with the requested capacity.
    • requestClose

      public void requestClose(WritableMemory memToClose, WritableMemory newMemory)
      Description copied from interface: MemoryRequestServer
      Request to close the resource, if applicable.
      Specified by:
      requestClose in interface MemoryRequestServer
      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.