Class MemorySegmentAllocator
java.lang.Object
eu.cloudnetservice.driver.impl.network.netty.memory.MemorySegmentAllocator
Unsafe allocator implementation for memory segments. Introduced to prevent checks when a shared arena (usually used
to allocate memory segments) is closed. This implementation just frees the provided memory segment, regardless of
possible in-flight usages.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final MethodHandleprivate static final MethodHandle -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidfree(@NonNull MemorySegment segment) Frees the memory block associated with the given memory segment.static @NonNull MemorySegmentmalloc(long byteCount) Allocates an off-heap memory block of the given requested size and returns anMemorySegmentthat wraps it.private static voidvalidateAllocatedSegment(@NonNull MemorySegment segment, long byteCount) Validates that the given memory segment was successfully allocated, throwing an exception if that is not the case.
-
Field Details
-
MALLOC
-
FREE
-
-
Constructor Details
-
MemorySegmentAllocator
MemorySegmentAllocator()
-
-
Method Details
-
validateAllocatedSegment
private static void validateAllocatedSegment(@NonNull @NonNull MemorySegment segment, long byteCount) Validates that the given memory segment was successfully allocated, throwing an exception if that is not the case.- Parameters:
segment- the segment to validate.byteCount- the requested byte count that should be allocated.- Throws:
NullPointerException- if the given segment is null.OutOfMemoryError- if the given segment was incorrectly allocated.
-
malloc
Allocates an off-heap memory block of the given requested size and returns anMemorySegmentthat wraps it. The memory is zeroed out.- Parameters:
byteCount- the count of bytes to allocate.- Returns:
- a memory segment wrapping the allocated block of memory.
- Throws:
IllegalStateException- if the invocation of the native malloc method failed.OutOfMemoryError- if the given byte count couldn't be reserved by the operating system.
-
free
Frees the memory block associated with the given memory segment.- Parameters:
segment- the segment representing the memory block to free.- Throws:
NullPointerException- if the given memory segment is null.IllegalStateException- if the invocation of the native free method failed.
-