BufferAllocator instances.
Two allocators are provided; one on-heap allocator, and one off-heap allocator.
These default allocators are configured via system properties.
These allocators cannot be closed directly.
They will instead be disposed of when the Runtime is shutdown.
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final BufferAllocator | |
| private static final BufferAllocator | |
| private static final BufferAllocator | |
| private static final InternalLogger |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static BufferAllocator | |
| public static BufferAllocator | |
| public static BufferAllocator | Returns: The shared, generally preferred allocator.Get the preferred, shared allocator. |
| DEFAULT_OFF_HEAP_ALLOCATOR | back to summary |
|---|---|
| private static final BufferAllocator DEFAULT_OFF_HEAP_ALLOCATOR | |
| DEFAULT_ON_HEAP_ALLOCATOR | back to summary |
|---|---|
| private static final BufferAllocator DEFAULT_ON_HEAP_ALLOCATOR | |
| DEFAULT_PREFERRED_ALLOCATOR | back to summary |
|---|---|
| private static final BufferAllocator DEFAULT_PREFERRED_ALLOCATOR | |
| logger | back to summary |
|---|---|
| private static final InternalLogger logger | |
| DefaultBufferAllocators | back to summary |
|---|---|
| private DefaultBufferAllocators() | |
| offHeapAllocator | back to summary |
|---|---|
| public static BufferAllocator offHeapAllocator() Get the shared off-heap allocator. This allocator always allocates off-heap buffers, and is either pooled, or unpooled.
| |
| onHeapAllocator | back to summary |
|---|---|
| public static BufferAllocator onHeapAllocator() Get the shared on-heap allocator. This allocator always allocates on-heap buffers, and is either pooled, or unpooled.
| |
| preferredAllocator | back to summary |
|---|---|
| public static BufferAllocator preferredAllocator() Get the preferred, shared allocator. This allocator is either on- or off-heap, and either pooling or unpooled, depending on the global configuration.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final BufferAllocator |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Buffer | allocate(int
The size of size)Buffer to allocate.Implements io. Buffer of the given size in bytes.
|
| public void | close()
Implements io. |
| public Supplier | constBufferSupplier(byte[]
The byte contents of the buffers produced by the returned supplier. bytes)Implements io. |
| public AllocationType | getAllocationType()
Implements io. AllocationType from this allocator.
|
| public boolean | isPooling()
Implements io. |
| delegate | back to summary |
|---|---|
| private final BufferAllocator delegate | |
| UncloseableBufferAllocator | back to summary |
|---|---|
| pack-priv UncloseableBufferAllocator(BufferAllocator delegate) | |
| allocate | back to summary |
|---|---|
| public Buffer allocate(int size) Implements io. Doc from io. Allocate a The buffer will use big endian byte order. Note unlike the JDK | |
| close | back to summary |
|---|---|
| public void close() Implements io. Doc from io. Close this allocator, freeing all of its internal resources. Existing (currently in-use) allocated buffers will not be impacted by calling this method. If this is a pooling or caching allocator, then existing buffers will be immediately freed when they are closed, instead of being pooled or cached.
The allocator can no longer be used to allocate more buffers after calling this method.
Attempting to allocate from a closed allocator will cause
| |
| constBufferSupplier | back to summary |
|---|---|
| public Supplier Implements io. Doc from io. Create a supplier of "constant" Buffers from this allocator, that all have the given byte contents. The buffer has the same capacity as the byte array length, and its write offset is placed at the end, and its read offset is at the beginning, such that the entire buffer contents are readable. The buffers produced by the supplier will each have their own independent life-cycle, and closing them will make them inaccessible, just like normally allocated buffers. The buffers produced are "constants", in the sense that they are read-only. It can generally be expected, but is not guaranteed, that the returned supplier is more resource efficient than allocating and copying memory with other available APIs. In such optimised implementations, the underlying memory baking the buffers will be shared among all the buffers produced by the supplier.
The primary use case for this API, is when you need to repeatedly produce buffers with the same contents, and
you perhaps wish to keep a | |
| getAllocationType | back to summary |
|---|---|
| public AllocationType getAllocationType() Implements io. Doc from io. Get the
| |
| isPooling | back to summary |
|---|---|
| public boolean isPooling() Implements io. Doc from io. Determine if this allocator is pooling and reusing its allocated memory.
| |