Package 

Class SharedByteArray

  • All Implemented Interfaces:
    com.facebook.common.memory.MemoryTrimmable

    @ThreadSafe() 
    public class SharedByteArray
     implements MemoryTrimmable
                        

    Maintains a shareable reference to a byte array.

    When accessing the shared array proper synchronization is guaranteed. Under hood the get method acquires an exclusive lock, which is released whenever the returned CloseableReference is closed.

    If the currently available byte array is too small for a request it is replaced with a bigger one.

    This class will also release the byte array if it is unused and collecting it can prevent an OOM.

    • Constructor Summary

      Constructors 
      Constructor Description
      SharedByteArray(MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams params)
    • Method Summary

      Modifier and Type Method Description
      CloseableReference<Array<byte>> get(int size) Get exclusive access to the byte array of size greater or equal to the passed one.
      void trim(MemoryTrimType trimType) Responds to memory pressure by simply 'discarding' the local byte array if it is not used atthe moment.
      • Methods inherited from class com.facebook.common.memory.MemoryTrimmable

        trim
      • Methods inherited from class java.lang.Object

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

      • SharedByteArray

        SharedByteArray(MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams params)
    • Method Detail

      • get

         CloseableReference<Array<byte>> get(int size)

        Get exclusive access to the byte array of size greater or equal to the passed one.

        Under the hood this method acquires an exclusive lock that is released when the returnedreference is closed.

      • trim

         void trim(MemoryTrimType trimType)

        Responds to memory pressure by simply 'discarding' the local byte array if it is not used atthe moment.

        Parameters:
        trimType - kind of trimming to perform (ignored)