@Internal public final class MemorySegmentFactory extends Object
HybridMemorySegment
).
The purpose of this factory is to make sure that all memory segments for heap data are of the
same type. That way, the runtime does not mix the various specializations of the MemorySegment
. Not mixing them has shown to be beneficial to method specialization by the JIT
and to overall performance.
Constructor and Description |
---|
MemorySegmentFactory() |
Modifier and Type | Method and Description |
---|---|
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 |
wrapPooledHeapMemory(byte[] memory,
Object owner)
Creates a memory segment that wraps the given byte array.
|
static MemorySegment |
wrapPooledOffHeapMemory(ByteBuffer memory,
Object owner)
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 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 wrapPooledHeapMemory(byte[] memory, Object owner)
This method is intended to be used for components which pool memory and create memory segments around long-lived memory regions.
memory
- The heap memory to be represented by the memory segment.owner
- The owner to associate with the memory segment.public static MemorySegment wrapPooledOffHeapMemory(ByteBuffer memory, Object owner)
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.owner
- The owner to associate with the memory segment.Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.