@Internal public final class MemorySegmentFactory extends Object
MemorySegment
).Constructor and Description |
---|
MemorySegmentFactory() |
Modifier and Type | Method and Description |
---|---|
static MemorySegment |
allocateOffHeapUnsafeMemory(int size) |
static MemorySegment |
allocateOffHeapUnsafeMemory(int size,
Object owner,
Runnable customCleanupAction)
Allocates an off-heap unsafe memory and creates a new memory segment to represent that
memory.
|
static MemorySegment |
allocateUnpooledOffHeapMemory(int size)
Allocates some unpooled off-heap memory and creates a new memory segment that represents that
memory.
|
static MemorySegment |
allocateUnpooledOffHeapMemory(int size,
Object owner)
Allocates some unpooled off-heap memory and creates a new memory segment that represents that
memory.
|
static MemorySegment |
allocateUnpooledSegment(int size)
Allocates some unpooled memory and creates a new memory segment that represents that memory.
|
static MemorySegment |
allocateUnpooledSegment(int size,
Object owner)
Allocates some unpooled memory and creates a new memory segment that represents that memory.
|
static MemorySegment |
wrap(byte[] buffer)
Creates a new memory segment that targets the given heap memory region.
|
static MemorySegment |
wrapCopy(byte[] bytes,
int start,
int end)
Copies the given heap memory region and creates a new memory segment wrapping it.
|
static MemorySegment |
wrapInt(int value)
Wraps the four bytes representing the given number with a
MemorySegment . |
static MemorySegment |
wrapOffHeapMemory(ByteBuffer memory)
Creates a memory segment that wraps the off-heap memory backing the given ByteBuffer.
|
public static MemorySegment wrap(byte[] buffer)
This method should be used to turn short lived byte arrays into memory segments.
buffer
- The heap memory region.public static MemorySegment wrapCopy(byte[] bytes, int start, int end) throws IllegalArgumentException
bytes
- The heap memory region.start
- starting position, inclusiveend
- end position, exclusiveIllegalArgumentException
- if start > end or end > bytes.lengthpublic static MemorySegment wrapInt(int value)
MemorySegment
.ByteBuffer.putInt(int)
public static MemorySegment allocateUnpooledSegment(int size)
This method is similar to allocateUnpooledSegment(int, Object)
, but the memory
segment will have null as the owner.
size
- The size of the memory segment to allocate.public static MemorySegment allocateUnpooledSegment(int size, Object owner)
This method is similar to allocateUnpooledSegment(int)
, but additionally sets the
owner of the memory segment.
size
- The size of the memory segment to allocate.owner
- The owner to associate with the memory segment.public static MemorySegment allocateUnpooledOffHeapMemory(int size)
size
- The size of the off-heap memory segment to allocate.public static MemorySegment allocateUnpooledOffHeapMemory(int size, Object owner)
size
- The size of the off-heap memory segment to allocate.owner
- The owner to associate with the off-heap memory segment.@VisibleForTesting public static MemorySegment allocateOffHeapUnsafeMemory(int size)
public static MemorySegment allocateOffHeapUnsafeMemory(int size, Object owner, Runnable customCleanupAction)
Creation of this segment schedules its memory freeing operation when its java wrapping
object is about to be garbage collected, similar to DirectByteBuffer(int)
. The difference is that this memory
allocation is out of option -XX:MaxDirectMemorySize limitation.
size
- The size of the off-heap unsafe memory segment to allocate.owner
- The owner to associate with the off-heap unsafe memory segment.customCleanupAction
- A custom action to run upon calling GC cleaner.public static MemorySegment wrapOffHeapMemory(ByteBuffer memory)
This method is intended to be used for components which pool memory and create memory segments around long-lived memory regions.
memory
- The byte buffer with the off-heap memory to be represented by the memory
segment.Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.