-
- All Implemented Interfaces:
-
com.facebook.common.memory.MemoryTrimmable
@ThreadSafe() public class SharedByteArray implements MemoryTrimmableMaintains 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. voidtrim(MemoryTrimType trimType)Responds to memory pressure by simply 'discarding' the local byte array if it is not used atthe moment. -
-
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)
-
-
-
-