MemoryManager implementation also determines the choice of Buffer implementation.
It is the MemoryManager that implement memory allocation, and how to wrap the allocated memory in a Buffer
interface.
API Note
This is a low-level, unstable, API that is used for
BufferAllocator implementations to build upon.
The methods in this interface are unsafe, because they can be used to violate the safety guarantees of the
Buffer API, and potentially also the safety guarantees of the JVM.
| Modifier and Type | Method and Description |
|---|---|
| public Buffer | Returns: A const buffer with the same size, contents, and read-only state of the given parent buffer.The read-only parent buffer for which a const buffer should be created. The parent
buffer is allocated in the usual way, with
readOnlyConstParent)allocateShared(AllocatorControl, long, Function, AllocationType),
initialised with contents, and then made read-only.Allocates a constant buffer based on the given parent. |
| public Buffer | Returns: ABuffer instance with the given configuration.Call-back interface for controlling the allocator that
requested the allocation of this buffer. allocatorControl, long The size of the buffer to allocate. This size is assumed to be valid for the implementation. size, Function<Drop<Buffer>, Drop<Buffer>> dropDecorator, AllocationType The type of allocation to perform.
Typically, one of the StandardAllocationTypes. allocationType)Allocates a shared buffer. |
| public static Stream | Returns: A stream of providers of memory managers instances.Get a stream of all available memory managers. |
| public void | clearMemory(Object
The memory that should be overwritten. memory)Overwrite the given recoverable memory object with zeroes, erasing all data that it contains. |
| public String | Returns: The name of this memory managers implementation.Get the name for this implementation, which can be used for finding this particular implementation via the
|
| public static MemoryManager | Returns: A MemoryManagers instance.Get the default, or currently configured, memory managers instance. |
| public static Optional | Returns: AMemoryManager implementation, if any was found.The named implementation to look for. implementationName)Find a |
| public static SafeCloseable | Returns: AnSafeCloseable instance that, when closed, removes the given callback again.The callback that will be called when a buffer leak is detected. callback)Register a callback that will be called whenever a |
| public Buffer | Returns: ABuffer instance backed by the given recovered memory.The allocator control to attach to the buffer. allocatorControl, Object The opaque memory to use for the buffer. recoverableMemory, Drop<Buffer> drop)Recover the memory from a prior |
| public Object | Returns: A new opaque memory instance that represents the given slice of the original.The opaque memory to slice. memory, int The offset into the memory to slice from. offset, int The length of the slice. length)Produces a slice of the given internal memory representation object. |
| public static Buffer | Returns: A buffer that wraps the given byte arrayThe byte array that will be embedded in the created buffer. array)Create a new on-heap |
| public Object | Returns: The internal memory of the given buffer, as an opaque object.The buffer to unwrap. buf)Create an object that represents the internal memory of the given buffer. |
| public static < The result type from the supplier. T> T | Returns: The result from the supplier.Override the default configured managers instance with this instance. manager, Supplier<T> The supplier function to be called while the override is in place. supplier)Temporarily override the default configured memory managers instance. |
| allocateConstChild | back to summary |
|---|---|
| public Buffer allocateConstChild(Buffer readOnlyConstParent) Allocates a constant buffer based on the given parent. A "constant" buffer is conceptually similar to a read-only
buffer, but the implementation may share the underlying memory across multiple buffer instance - something that
is normally not allowed by the API. This allows efficient implementation of the
Note The const-parent buffer must be allocated by this memory manager.
| |
| allocateShared | back to summary |
|---|---|
| public Buffer allocateShared(AllocatorControl allocatorControl, long size, Function<Drop<Buffer>, Drop<Buffer>> dropDecorator, AllocationType allocationType) Allocates a shared buffer. "Shared" is the normal type of buffer, and means the buffer permit concurrent access
from multiple threads, within the limited thread-safety guarantees of the
| |
| availableManagers | back to summary |
|---|---|
| public static Stream Get a stream of all available memory managers.
| |
| clearMemory | back to summary |
|---|---|
| public void clearMemory(Object memory) Overwrite the given recoverable memory object with zeroes, erasing all data that it contains.
This is used by the
| |
| implementationName | back to summary |
|---|---|
| public String implementationName() Get the name for this implementation, which can be used for finding this particular implementation via the
| |
| instance | back to summary |
|---|---|
| public static MemoryManager instance() Get the default, or currently configured, memory managers instance.
| |
| lookupImplementation | back to summary |
|---|---|
| public static Optional Find a
| |
| onLeakDetected | back to summary |
|---|---|
| public static SafeCloseable onLeakDetected(Consumer<LeakInfo> callback) Register a callback that will be called whenever a Be mindful that the callback must be fast, and not take any locks or call any blocking methods, as this might interfere with the garbage collectors reference processing and cleaning. This also applies to callbacks that perform logging. In these cases, asynchronous logging should be preferred, for the avoidance of blocking calls and IO.
If the same callback object is registered multiple times, it will only be informed once for each leak,
but each of the associated
| |
| recoverMemory | back to summary |
|---|---|
| public Buffer recoverMemory(AllocatorControl allocatorControl, Object recoverableMemory, Drop<Buffer> drop) Recover the memory from a prior | |
| sliceMemory | back to summary |
|---|---|
| public Object sliceMemory(Object memory, int offset, int length) Produces a slice of the given internal memory representation object. | |
| unsafeWrap | back to summary |
|---|---|
| public static Buffer unsafeWrap(byte[] array) Create a new on-heap This is unsafe because it allows the memory (the array) to be aliased (multiple references to the same memory) in an uncontrolled way. The returned buffer will be read-only, but changes to the byte array will be reflected in the buffers contents. Note Wrapping buffers created with this method are not subject to leak detection, and if they are garbage collected without being closed first, then no callback will be issued to any on-leak callback handler.
| |
| unwrapRecoverableMemory | back to summary |
|---|---|
| public Object unwrapRecoverableMemory(Buffer buf) Create an object that represents the internal memory of the given buffer. | |
| using | back to summary |
|---|---|
| public static <T> T using(MemoryManager manager, Supplier<T> supplier) Temporarily override the default configured memory managers instance.
Calls to
| |