Class UnsafeMemoryManager

  • All Implemented Interfaces:
    MemoryManager

    public final class UnsafeMemoryManager
    extends Object
    implements MemoryManager
    This memory manager produces and manages Buffer instances that are using Unsafe to allocate and access memory.

    Memory managers are normally not used directly. Instead, you likely want to use the DefaultBufferAllocators, or the static methods on BufferAllocator.

    • Constructor Detail

      • UnsafeMemoryManager

        public UnsafeMemoryManager()
    • Method Detail

      • allocateShared

        public Buffer allocateShared​(AllocatorControl control,
                                     long size,
                                     Function<Drop<Buffer>,​Drop<Buffer>> dropDecorator,
                                     AllocationType allocationType)
        Description copied from interface: MemoryManager
        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 Buffer interface.
        Specified by:
        allocateShared in interface MemoryManager
        Parameters:
        control - Call-back interface for controlling the allocator that requested the allocation of this buffer.
        size - The size of the buffer to allocate. This size is assumed to be valid for the implementation.
        dropDecorator - A function to decorate the memory managers Drop instance. The Drop instance returned by this function will be used when the buffer is closed.
        allocationType - The type of allocation to perform. Typically, one of the StandardAllocationTypes.
        Returns:
        A Buffer instance with the given configuration.
      • allocateConstChild

        public Buffer allocateConstChild​(Buffer readOnlyConstParent)
        Description copied from interface: MemoryManager
        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 BufferAllocator.constBufferSupplier(byte[]) method.

        Note: The const-parent buffer must be allocated by this memory manager.

        Specified by:
        allocateConstChild in interface MemoryManager
        Parameters:
        readOnlyConstParent - The read-only parent buffer for which a const buffer should be created. The parent buffer is allocated in the usual way, with MemoryManager.allocateShared(AllocatorControl, long, Function, AllocationType), initialised with contents, and then made read-only.
        Returns:
        A const buffer with the same size, contents, and read-only state of the given parent buffer.
      • unwrapRecoverableMemory

        public Object unwrapRecoverableMemory​(Buffer buf)
        Description copied from interface: MemoryManager
        Create an object that represents the internal memory of the given buffer.
        Specified by:
        unwrapRecoverableMemory in interface MemoryManager
        Parameters:
        buf - The buffer to unwrap.
        Returns:
        The internal memory of the given buffer, as an opaque object.
      • sliceMemory

        public Object sliceMemory​(Object memory,
                                  int offset,
                                  int length)
        Description copied from interface: MemoryManager
        Produces a slice of the given internal memory representation object.
        Specified by:
        sliceMemory in interface MemoryManager
        Parameters:
        memory - The opaque memory to slice.
        offset - The offset into the memory to slice from.
        length - The length of the slice.
        Returns:
        A new opaque memory instance that represents the given slice of the original.
      • clearMemory

        public void clearMemory​(Object memory)
        Description copied from interface: MemoryManager
        Overwrite the given recoverable memory object with zeroes, erasing all data that it contains.

        This is used by the SensitiveBufferAllocator to erase data on deallocation.

        Specified by:
        clearMemory in interface MemoryManager
        Parameters:
        memory - The memory that should be overwritten.