Class PlatformMemoryUtils


  • public class PlatformMemoryUtils
    extends Object
    Utility classes for memory management.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long allocatePool()
      Allocate pool memory.
      static long allocatePooled​(long poolPtr, int cap)
      Allocate pooled memory chunk.
      static long allocateUnpooled​(int cap)
      Allocate unpooled memory chunk.
      static int capacity​(long memPtr)
      Gets capacity for the given memory chunk.
      static void capacity​(long memPtr, int cap)
      Sets capacity for the given memory chunk.
      static long data​(long memPtr)
      Gets data pointer for the given memory chunk.
      static int flags​(long memPtr)
      Gets flags for the given memory chunk.
      static void flags​(long memPtr, int flags)
      Sets flags for the given memory chunk.
      static boolean isAcquired​(int flags)
      Check whether flags denote pooled and acquired memory chunk.
      static boolean isAcquired​(long memPtr)
      Check whether this memory chunk is pooled and acquired.
      static boolean isExternal​(int flags)
      Check whether flags denote that this memory chunk is external.
      static boolean isExternal​(long memPtr)
      Check whether this memory chunk is external.
      static boolean isPooled​(int flags)
      Check whether flags denote pooled memory chunk.
      static boolean isPooled​(long memPtr)
      Check whether this memory chunk is pooled.
      static int length​(long memPtr)
      Gets length for the given memory chunk.
      static void length​(long memPtr, int len)
      Sets length for the given memory chunk.
      static void reallocate​(long memPtr, int cap)
      Reallocate arbitrary memory chunk.
      static void reallocatePooled​(long memPtr, int cap)
      Reallocate pooled memory chunk.
      static void reallocateUnpooled​(long memPtr, int cap)
      Reallocate unpooled memory chunk.
      static void releasePool​(long poolPtr)
      Release pool memory.
      static void releasePooled​(long memPtr)
      Release pooled memory chunk.
      static void releaseUnpooled​(long memPtr)
      Release unpooled memory chunk.
    • Field Detail

      • POOL_HDR_OFF_MEM_1

        public static final int POOL_HDR_OFF_MEM_1
        Pool header offset: first memory chunk.
        See Also:
        Constant Field Values
      • POOL_HDR_OFF_MEM_2

        public static final int POOL_HDR_OFF_MEM_2
        Pool header offset: second memory chunk.
        See Also:
        Constant Field Values
      • POOL_HDR_OFF_MEM_3

        public static final int POOL_HDR_OFF_MEM_3
        Pool header offset: third memory chunk.
        See Also:
        Constant Field Values
      • MEM_HDR_LEN

        public static final int MEM_HDR_LEN
        Memory chunk header length.
        See Also:
        Constant Field Values
      • MEM_HDR_OFF_CAP

        public static final int MEM_HDR_OFF_CAP
        Offset: capacity.
        See Also:
        Constant Field Values
      • MEM_HDR_OFF_LEN

        public static final int MEM_HDR_OFF_LEN
        Offset: length.
        See Also:
        Constant Field Values
      • MEM_HDR_OFF_FLAGS

        public static final int MEM_HDR_OFF_FLAGS
        Offset: flags.
        See Also:
        Constant Field Values
      • FLAG_ACQUIRED

        public static final int FLAG_ACQUIRED
        Flag: whether this pooled memory chunk is acquired.
        See Also:
        Constant Field Values
    • Method Detail

      • data

        public static long data​(long memPtr)
        Gets data pointer for the given memory chunk.
        Parameters:
        memPtr - Memory pointer.
        Returns:
        Data pointer.
      • capacity

        public static int capacity​(long memPtr)
        Gets capacity for the given memory chunk.
        Parameters:
        memPtr - Memory pointer.
        Returns:
        Capacity.
      • capacity

        public static void capacity​(long memPtr,
                                    int cap)
        Sets capacity for the given memory chunk.
        Parameters:
        memPtr - Memory pointer.
        cap - Capacity.
      • length

        public static int length​(long memPtr)
        Gets length for the given memory chunk.
        Parameters:
        memPtr - Memory pointer.
        Returns:
        Length.
      • length

        public static void length​(long memPtr,
                                  int len)
        Sets length for the given memory chunk.
        Parameters:
        memPtr - Memory pointer.
        len - Length.
      • flags

        public static int flags​(long memPtr)
        Gets flags for the given memory chunk.
        Parameters:
        memPtr - Memory pointer.
        Returns:
        Flags.
      • flags

        public static void flags​(long memPtr,
                                 int flags)
        Sets flags for the given memory chunk.
        Parameters:
        memPtr - Memory pointer.
        flags - Flags.
      • isExternal

        public static boolean isExternal​(long memPtr)
        Check whether this memory chunk is external.
        Parameters:
        memPtr - Memory pointer.
        Returns:
        True if owned by native platform.
      • isExternal

        public static boolean isExternal​(int flags)
        Check whether flags denote that this memory chunk is external.
        Parameters:
        flags - Flags.
        Returns:
        True if owned by native platform.
      • isPooled

        public static boolean isPooled​(long memPtr)
        Check whether this memory chunk is pooled.
        Parameters:
        memPtr - Memory pointer.
        Returns:
        True if pooled.
      • isPooled

        public static boolean isPooled​(int flags)
        Check whether flags denote pooled memory chunk.
        Parameters:
        flags - Flags.
        Returns:
        True if pooled.
      • isAcquired

        public static boolean isAcquired​(long memPtr)
        Check whether this memory chunk is pooled and acquired.
        Parameters:
        memPtr - Memory pointer.
        Returns:
        True if pooled and acquired.
      • isAcquired

        public static boolean isAcquired​(int flags)
        Check whether flags denote pooled and acquired memory chunk.
        Parameters:
        flags - Flags.
        Returns:
        True if acquired.
      • allocateUnpooled

        public static long allocateUnpooled​(int cap)
        Allocate unpooled memory chunk.
        Parameters:
        cap - Minimum capacity.
        Returns:
        New memory pointer.
      • reallocateUnpooled

        public static void reallocateUnpooled​(long memPtr,
                                              int cap)
        Reallocate unpooled memory chunk.
        Parameters:
        memPtr - Memory pointer.
        cap - Minimum capacity.
      • releaseUnpooled

        public static void releaseUnpooled​(long memPtr)
        Release unpooled memory chunk.
        Parameters:
        memPtr - Memory pointer.
      • allocatePool

        public static long allocatePool()
        Allocate pool memory.
        Returns:
        Pool pointer.
      • releasePool

        public static void releasePool​(long poolPtr)
        Release pool memory.
        Parameters:
        poolPtr - Pool pointer.
      • allocatePooled

        public static long allocatePooled​(long poolPtr,
                                          int cap)
        Allocate pooled memory chunk.
        Parameters:
        poolPtr - Pool pointer.
        cap - Capacity.
        Returns:
        Cross-platform memory pointer or 0 in case there are no free memory chunks in the pool.
      • reallocatePooled

        public static void reallocatePooled​(long memPtr,
                                            int cap)
        Reallocate pooled memory chunk.
        Parameters:
        memPtr - Memory pointer.
        cap - Minimum capacity.
      • releasePooled

        public static void releasePooled​(long memPtr)
        Release pooled memory chunk.
        Parameters:
        memPtr - Memory pointer.
      • reallocate

        public static void reallocate​(long memPtr,
                                      int cap)
        Reallocate arbitrary memory chunk.
        Parameters:
        memPtr - Memory pointer.
        cap - Capacity.