Class ByteBuffersSoftCache


  • public class ByteBuffersSoftCache
    extends SizedSoftCache<java.nio.ByteBuffer>
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.nio.ByteBuffer create​(int size)
      When the cache runs empty, further allocations must create new objects.
      protected int dynamicEach​(int size)
      Implementations must provide a function that estimates the GC impact of an instance of a given size.
      static java.nio.ByteBuffer get​(int size)
      Obtain a ByteBuffer instance with a capacity at least the given size.
      protected boolean qualified​(java.nio.ByteBuffer recycled)
      An item returned from a user might have been changed in a way that makes it unsuitable for reuse.
      static void release​(java.nio.ByteBuffer recycle)  
      protected int sizeOf​(java.nio.ByteBuffer recycle)
      When an object is freed for recycling, its size must be examined to determine the appropriate nested cache to use, and whether it exactly matches that cache.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • get

        public static java.nio.ByteBuffer get​(int size)
        Obtain a ByteBuffer instance with a capacity at least the given size. It will be recycled back into this cache by the garbage collector if memory pressure permits.

        As this library mostly deals with little-endian data, the returned ByteBuffer is configured with that order.

        Parameters:
        size -
        Returns:
      • release

        public static void release​(java.nio.ByteBuffer recycle)
      • dynamicEach

        protected int dynamicEach​(int size)
        Description copied from class: SizedSoftCache
        Implementations must provide a function that estimates the GC impact of an instance of a given size.
        Specified by:
        dynamicEach in class SizedSoftCache<java.nio.ByteBuffer>
        Returns:
      • sizeOf

        protected int sizeOf​(java.nio.ByteBuffer recycle)
        Description copied from class: SizedSoftCache
        When an object is freed for recycling, its size must be examined to determine the appropriate nested cache to use, and whether it exactly matches that cache.
        Specified by:
        sizeOf in class SizedSoftCache<java.nio.ByteBuffer>
        Returns:
        The actual size of the object to recycle.
      • qualified

        protected boolean qualified​(java.nio.ByteBuffer recycled)
        Description copied from class: SizedSoftCache
        An item returned from a user might have been changed in a way that makes it unsuitable for reuse. This method gives the implementation a chance to verify that and/or make corrections.
        Specified by:
        qualified in class SizedSoftCache<java.nio.ByteBuffer>
        Parameters:
        recycled - The subject item that is to be placed back in this cache's fast access list.
        Returns:
        True if ready for re-use, false if to be discarded.
      • create

        protected java.nio.ByteBuffer create​(int size)
        Description copied from class: SizedSoftCache
        When the cache runs empty, further allocations must create new objects. Since the queue is based on soft references, the garbage collector can throw some away at will.
        Specified by:
        create in class SizedSoftCache<java.nio.ByteBuffer>
        Returns: