@Internal public class MemorySegmentFactory extends Object
MemorySegment
. Not mixing them has shown to be beneficial
to method specialization by the JIT and to overall performance.
Note that this factory auto-initialized to use HeapMemorySegment
,
if a request to create a segment comes before the initialization.
Modifier and Type | Class and Description |
---|---|
static interface |
MemorySegmentFactory.Factory
A concrete factory for memory segments.
|
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 MemorySegmentFactory.Factory |
getFactory()
Gets the factory.
|
static void |
initializeFactory(MemorySegmentFactory.Factory f)
Initializes this factory with the given concrete factory.
|
static boolean |
isInitialized()
Checks whether this memory segment factory has been initialized (with a type to produce).
|
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)
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.public static void initializeFactory(MemorySegmentFactory.Factory f)
f
- The concrete factory to use.IllegalStateException
- Thrown, if this factory has been initialized before.public static boolean isInitialized()
public static MemorySegmentFactory.Factory getFactory()
Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.