Class NIOBuffersInterop


  • public class NIOBuffersInterop
    extends Object
    NIO buffers interoperability
    Author:
    royer
    • Constructor Detail

      • NIOBuffersInterop

        public NIOBuffersInterop()
    • Method Detail

      • getContiguousMemoryFrom

        public static OffHeapMemory getContiguousMemoryFrom​(Buffer pBuffer)
        Returns a contiguous buffer from a NIO buffer
        Parameters:
        pBuffer - NIO buffer
        Returns:
        contiguous memory
      • getByteBuffersForContiguousMemory

        public static ArrayList<ByteBuffer> getByteBuffersForContiguousMemory​(ContiguousMemoryInterface pContiguousMemory,
                                                                              long pPositionInBytes,
                                                                              long pLengthInBytes)
        This method creates a list of ByteBuffers that cover sequentially a given ContiguousMemory region. This should only be used within the CoreMem classes. It's use is tricky... IMPORTANT: the bytebuffers returned do not hold references to the parent responsible for the memory lifecycle. This means that the references of these bytebuffers cannot escape the scope within which the ContiguousMemory reference is held. If the GC cleans up the ContiguousMemory and there is still a returned ByteBuffer 'alive', this will necessarily lead to a segmentation fault.
        Parameters:
        pContiguousMemory - contiguous memory
        pPositionInBytes - position in bytes
        pLengthInBytes - length in bytes
        Returns:
        array of NIO byte buffers corresponding to given contiguous memory region