Class MemorySegmentRequestExample
java.lang.Object
org.apache.datasketches.common.MemorySegmentRequestExample
- All Implemented Interfaces:
MemorySegmentRequest
This is an example of a possible implementation of the MemorySegmentRequest interface
where all requested segments are allocated off-heap. A local ConcurrentHashMap tracks a newly created
confined Arena for every new MemorySegment allocated off-heap. This allows individual segments to be freed
immediately upon receiving the
requestClose(MemorySegment) call.-
Nested Class Summary
Nested classes/interfaces inherited from interface MemorySegmentRequest
MemorySegmentRequest.Default -
Field Summary
Fields inherited from interface MemorySegmentRequest
DEFAULT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanup()This closes any unclosed, off-heap MemorySegments and removes all mappings from the map.request(long newByteSize) Request a new off-heap MemorySegment with the given newByteSeze.voidrequestClose(MemorySegment segKey) Request to close the given MemorySegment.
-
Constructor Details
-
MemorySegmentRequestExample
public MemorySegmentRequestExample()No argument constructor.
-
-
Method Details
-
request
Request a new off-heap MemorySegment with the given newByteSeze. An internal confined Arena is created to exclusively manage the new segment and it is associated with the new segment with a ConcurrentHashMap.- Specified by:
requestin interfaceMemorySegmentRequest- Parameters:
newByteSize- The new byteSize being requested.- Returns:
- new MemorySegment with the requested byteSize.
-
requestClose
Description copied from interface:MemorySegmentRequestRequest to close the given MemorySegment. Because we do not have a reference to an Arena, the default here is to do nothing. It is up to the user to override this as appropriate.- Specified by:
requestClosein interfaceMemorySegmentRequest- Parameters:
segKey- the previous MemorySegment to be closed.
-
cleanup
public void cleanup()This closes any unclosed, off-heap MemorySegments and removes all mappings from the map.
-