public class

GenericByteArrayPool

extends BasePool<V>
implements ByteArrayPool
java.lang.Object
   ↳ com.facebook.imagepipeline.memory.BasePool<V>
     ↳ com.facebook.imagepipeline.memory.GenericByteArrayPool

Class Overview

A pool of byte arrays. The pool manages a number of byte arrays of a predefined set of sizes. This set of sizes is typically, but not required to be, based on powers of 2. The pool supports a get/release paradigm. On a get request, the pool attempts to find an existing byte array whose size is at least as big as the requested size. On a release request, the pool adds the byte array to the appropriate bucket. This byte array can then be used for a subsequent get request.

Summary

Public Constructors
GenericByteArrayPool(MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker)
Creates a new instance of the GenericByteArrayPool class
Public Methods
int getMinBufferSize()
Gets the smallest buffer size supported by the pool
Protected Methods
byte[] alloc(int bucketedSize)
Allocate a buffer greater than or equal to the specified size
void free(byte[] value)
Frees the 'value'
int getBucketedSize(int requestSize)
Get the 'bucketed' size for the given request size.
int getBucketedSizeForValue(byte[] value)
Gets the bucketed size of the value
int getSizeInBytes(int bucketedSize)
Gets the size in bytes for the given 'bucketed' size
[Expand]
Inherited Methods
From class com.facebook.imagepipeline.memory.BasePool
From class java.lang.Object
From interface com.facebook.common.memory.MemoryTrimmable
From interface com.facebook.common.memory.Pool
From interface com.facebook.common.references.ResourceReleaser

Public Constructors

public GenericByteArrayPool (MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker)

Creates a new instance of the GenericByteArrayPool class

Parameters
memoryTrimmableRegistry the memory manager to register with
poolParams provider for pool parameters

Public Methods

public int getMinBufferSize ()

Gets the smallest buffer size supported by the pool

Returns
  • the smallest buffer size supported by the pool

Protected Methods

protected byte[] alloc (int bucketedSize)

Allocate a buffer greater than or equal to the specified size

Parameters
bucketedSize size of the buffer requested
Returns
  • a byte array of the specified or larger size. Null if the size is invalid

protected void free (byte[] value)

Frees the 'value'

Parameters
value the value to free

protected int getBucketedSize (int requestSize)

Get the 'bucketed' size for the given request size. The 'bucketed' size is a size that is the same or larger than the request size. We walk through our list of pre-defined bucket sizes, and use that to determine the smallest bucket size that is larger than the requested size. If no such 'bucketedSize' is found, then we simply return "requestSize"

Parameters
requestSize the logical request size
Returns
  • the bucketed size
Throws
if the requested size was invalid

protected int getBucketedSizeForValue (byte[] value)

Gets the bucketed size of the value

Parameters
value the value
Returns
  • just the length of the value

protected int getSizeInBytes (int bucketedSize)

Gets the size in bytes for the given 'bucketed' size

Parameters
bucketedSize the bucketed size
Returns
  • size in bytes