Class OffHeapMemory

    • Field Detail

      • mName

        protected String mName
      • mSignature

        protected Long mSignature
      • mParent

        protected Object mParent
    • Constructor Detail

      • OffHeapMemory

        public OffHeapMemory​(long pLengthInBytes)
        Allocates an off-heap memory region of given length in bytes.
        Parameters:
        pLengthInBytes - length in bytes
      • OffHeapMemory

        public OffHeapMemory​(String pName,
                             long pLengthInBytes)
        Allocates an off-heap memory region of given name and length in bytes.
        Parameters:
        pName - name
        pLengthInBytes - length in bytes
      • OffHeapMemory

        public OffHeapMemory​(Object pParent,
                             long pAddress,
                             long pLengthInBytes)
        Warps an off-heap memory region of given parent, address, and length in bytes.
        Parameters:
        pParent - parent
        pAddress - address
        pLengthInBytes - length in bytes
      • OffHeapMemory

        public OffHeapMemory​(String pName,
                             Object pParent,
                             long pAddress,
                             long pLengthInBytes)
        Warps an off-heap memory region of given name, parent, address, and length in bytes.
        Parameters:
        pName - name
        pParent - parent
        pAddress - address
        pLengthInBytes - length in bytes
    • Method Detail

      • wrapPointer

        public static final OffHeapMemory wrapPointer​(Object pParent,
                                                      long pAddress,
                                                      long pLengthInBytes)
        Wraps a 'raw' pointer i.e. a long pointer value and a length. This is used to wrap a non-coremem memory region. A parent can be given, to prevent its garbage collection and the possible release of the underlying memory resource.
        Parameters:
        pParent - parent reference to prevent the parent's garbage collection.
        pAddress - address
        pLengthInBytes - length in bytes
        Returns:
        off-heap memory object
      • wrapPointer

        public static final OffHeapMemory wrapPointer​(String pName,
                                                      Object pParent,
                                                      long pAddress,
                                                      long pLengthInBytes)
        Wraps a 'raw' pointer i.e. a long pointer value and a length. This is used to wrap a non-coremem memory region. A parent can be given, to prevent its garbage collection and the possible release of the underlying memory resource.
        Parameters:
        pName - memory region name
        pParent - parent reference to prevent the parent's garbage collection.
        pAddress - address
        pLengthInBytes - length in bytes
        Returns:
        off-heap memory object
      • wrapPointer

        public static OffHeapMemory wrapPointer​(com.sun.jna.Pointer pJNAPointer,
                                                long pTargetSizeInBytes)
        Wraps a JNA pointer.
        Parameters:
        pJNAPointer - JNA pointer
        pTargetSizeInBytes - ?
        Returns:
        off-heap memory object
      • wrapPointer

        @Deprecated
        public static OffHeapMemory wrapPointer​(com.sun.jna.Memory pJNAMemory)
        Deprecated.
        In an ideal world, this would wraps a JNA memory or pointer. But, because of a fatal design flaw in JNA: no automatic freeing on garbage collection. They do use 'finalise' horror! this is highly discouraged and a mostly deprecated feature of the JVM, it kills GC performance, why are they doing this?

        This static method here is meant to be educative and a deterrent to this pattern. It should not be used, cannot be used and is not functional anyway. You should always use CoreMem to allocate memory, because CoreMem does the right thing by freeing memory upon garbage collection. If you need a JNA memory, allocate a OffHeapMemory and pass a JNA pointer with getJNAPointer(). If you don't use this pattern, then you have to free the

        Parameters:
        pJNAMemory - JNA memory
        Returns:
        off-heap memory object
      • wrapPointer

        public static OffHeapMemory wrapPointer​(org.bridj.Pointer<Byte> pBridJPointer)
        Wraps a bridj pointer.
        Parameters:
        pBridJPointer - BridJ pointer
        Returns:
        off-heap memory object
      • wrapBuffer

        public static final OffHeapMemory wrapBuffer​(Buffer pBuffer)
        Wraps a NIO buffer.
        Parameters:
        pBuffer - NIO buffer
        Returns:
        off-heap memory object
      • copyFromArray

        public static final OffHeapMemory copyFromArray​(byte[] pBuffer)
        Creates a off-heap memory object initialized by copying the contents of a byte array.
        Parameters:
        pBuffer - buffer to copy contents from
        Returns:
        off-heap memory object
      • allocateBytes

        public static OffHeapMemory allocateBytes​(long pNumberOfBytes)
        Allocates off-heap memory that can hold a given number of bytes.
        Parameters:
        pNumberOfBytes - number of bytes
        Returns:
        off-heap memory object
      • allocateChars

        public static OffHeapMemory allocateChars​(long pNumberOfChars)
        Allocates off-heap memory that can hold a given number of chars.
        Parameters:
        pNumberOfChars - number of chars
        Returns:
        off-heap memory object
      • allocateShorts

        public static OffHeapMemory allocateShorts​(long pNumberOfShorts)
        Allocates off-heap memory that can hold a given number of shorts.
        Parameters:
        pNumberOfShorts - number of shorts
        Returns:
        off-heap memory object
      • allocateInts

        public static OffHeapMemory allocateInts​(long pNumberOfInts)
        Allocates off-heap memory that can hold a given number of ints.
        Parameters:
        pNumberOfInts - number of ints
        Returns:
        off-heap memory object
      • allocateLongs

        public static OffHeapMemory allocateLongs​(long pNumberOfLongs)
        Allocates off-heap memory that can hold a given number of longs.
        Parameters:
        pNumberOfLongs - number of longs
        Returns:
        off-heap memory object
      • allocateFloats

        public static OffHeapMemory allocateFloats​(long pNumberOfFloats)
        Allocates off-heap memory that can hold a given number of floats.
        Parameters:
        pNumberOfFloats - number of floats
        Returns:
        off-heap memory object
      • allocateDoubles

        public static OffHeapMemory allocateDoubles​(long pNumberOfDoubles)
        Allocates off-heap memory that can hold a given number of doubles.
        Parameters:
        pNumberOfDoubles - number of doubles
        Returns:
        off-heap memory object
      • allocateBytes

        public static OffHeapMemory allocateBytes​(String pName,
                                                  long pNumberOfBytes)
        Allocates off-heap memory that can hold a given number of bytes.
        Parameters:
        pName - name (can be used to track allocation origin)
        pNumberOfBytes - number of bytes
        Returns:
        off-heap memory object
      • allocateChars

        public static OffHeapMemory allocateChars​(String pName,
                                                  long pNumberOfChars)
        Allocates off-heap memory that can hold a given number of chars.
        Parameters:
        pName - name (can be used to track allocation origin)
        pNumberOfChars - number of chars
        Returns:
        off-heap memory object
      • allocateShorts

        public static OffHeapMemory allocateShorts​(String pName,
                                                   long pNumberOfShorts)
        Allocates off-heap memory that can hold a given number of shorts.
        Parameters:
        pName - name (can be used to track allocation origin)
        pNumberOfShorts - number of shorts
        Returns:
        off-heap memory object
      • allocateInts

        public static OffHeapMemory allocateInts​(String pName,
                                                 long pNumberOfInts)
        Allocates off-heap memory that can hold a given number of ints.
        Parameters:
        pName - name (can be used to track allocation origin)
        pNumberOfInts - number of ints
        Returns:
        off-heap memory object
      • allocateLongs

        public static OffHeapMemory allocateLongs​(String pName,
                                                  long pNumberOfLongs)
        Allocates off-heap memory that can hold a given number of longs.
        Parameters:
        pName - name (can be used to track allocation origin)
        pNumberOfLongs - number of longs
        Returns:
        off-heap memory object
      • allocateFloats

        public static OffHeapMemory allocateFloats​(String pName,
                                                   long pNumberOfFloats)
        Allocates off-heap memory that can hold a given number of floats.
        Parameters:
        pName - name (can be used to track allocation origin)
        pNumberOfFloats - number of floats
        Returns:
        off-heap memory object
      • allocateDoubles

        public static OffHeapMemory allocateDoubles​(String pName,
                                                    long pNumberOfDoubles)
        Allocates off-heap memory that can hold a given number of doubles.
        Parameters:
        pName - name (can be used to track allocation origin)
        pNumberOfDoubles - number of doubles
        Returns:
        off-heap memory object
      • allocatePageAlignedBytes

        public static OffHeapMemory allocatePageAlignedBytes​(String pName,
                                                             long pNumberOfBytes)
        Allocates page=aligned off-heap memory that can hold a given number of bytes.
        Parameters:
        pName - name (can be used to track allocation origin)
        pNumberOfBytes - number of bytes
        Returns:
        off-heap memory object
      • allocateAlignedBytes

        public static OffHeapMemory allocateAlignedBytes​(String pName,
                                                         long pNumberOfBytes,
                                                         long pAlignment)
        Allocates off-heap memory that can hold a given number of bytes, with a given alignment.
        Parameters:
        pName - name (can be used to track allocation origin)
        pNumberOfBytes - number of bytes
        pAlignment - byte boundary to align to.
        Returns:
        off-heap memory object
      • subRegion

        public OffHeapMemory subRegion​(long pOffset,
                                       long pLenghInBytes)
        Description copied from interface: ContiguousMemoryInterface
        Returns a contiguous memory object representing for a memory sub region.
        Specified by:
        subRegion in interface ContiguousMemoryInterface
        Parameters:
        pOffset - offset in bytes
        pLenghInBytes - length in bytes
        Returns:
        contiguous memory for sub region
      • resize

        public long resize​(long pNewLength)
        Description copied from interface: Resizable
        Resizes this memory object.
        Specified by:
        resize in interface Resizable
        Parameters:
        pNewLength - new length.
        Returns:
        new length
      • free

        public void free()
        Description copied from interface: Freeable
        Free this object, which means that the underlying ressources are released.
        Specified by:
        free in interface Freeable
        Overrides:
        free in class MemoryBase
      • getCleaner

        public Cleaner getCleaner()
        Description copied from interface: Cleanable
        Returns the cleaner for this object.
        Specified by:
        getCleaner in interface Cleanable
        Returns:
        cleaner runnable