com.facebook.common.memory.MemoryTrimmableRegistry Java Examples
The following examples show how to use
com.facebook.common.memory.MemoryTrimmableRegistry.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SingleByteArrayPool.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
/** * Creates an instance of the SingleByteArrayPool class, and registers it * @param memoryTrimmableRegistry the memory resource manager * @param singleByteArrayPoolStatsTracker stats tracker for the pool * @param minByteArraySize size of the smallest byte array we will create * @param maxByteArraySize size of the largest byte array we will create */ @VisibleForTesting SingleByteArrayPool( MemoryTrimmableRegistry memoryTrimmableRegistry, SingleByteArrayPoolStatsTracker singleByteArrayPoolStatsTracker, int minByteArraySize, int maxByteArraySize) { Preconditions.checkNotNull(memoryTrimmableRegistry); Preconditions.checkNotNull(singleByteArrayPoolStatsTracker); Preconditions.checkState(minByteArraySize > 0 && maxByteArraySize >= minByteArraySize); mSingleByteArrayPoolStatsTracker = singleByteArrayPoolStatsTracker; mMaxByteArraySize = maxByteArraySize; mMinByteArraySize = minByteArraySize; mByteArraySoftRef = new OOMSoftReference<byte[]>(); memoryTrimmableRegistry.registerMemoryTrimmable(this); }
Example #2
Source File: FlexByteArrayPoolTest.java From fresco with MIT License | 6 votes |
@Before public void setup() { SparseIntArray buckets = new SparseIntArray(); for (int i = MIN_BUFFER_SIZE; i <= MAX_BUFFER_SIZE; i *= 2) { buckets.put(i, 3); } mPool = new FlexByteArrayPool( mock(MemoryTrimmableRegistry.class), new PoolParams( Integer.MAX_VALUE, Integer.MAX_VALUE, buckets, MIN_BUFFER_SIZE, MAX_BUFFER_SIZE, 1)); mDelegatePool = mPool.mDelegatePool; }
Example #3
Source File: EncodedCountingMemoryCacheFactory.java From fresco with MIT License | 6 votes |
public static CountingMemoryCache<CacheKey, PooledByteBuffer> get( Supplier<MemoryCacheParams> encodedMemoryCacheParamsSupplier, MemoryTrimmableRegistry memoryTrimmableRegistry) { ValueDescriptor<PooledByteBuffer> valueDescriptor = new ValueDescriptor<PooledByteBuffer>() { @Override public int getSizeInBytes(PooledByteBuffer value) { return value.size(); } }; CountingMemoryCache.CacheTrimStrategy trimStrategy = new NativeMemoryCacheTrimStrategy(); CountingMemoryCache<CacheKey, PooledByteBuffer> countingCache = new CountingMemoryCache<>( valueDescriptor, trimStrategy, encodedMemoryCacheParamsSupplier, null); memoryTrimmableRegistry.registerMemoryTrimmable(countingCache); return countingCache; }
Example #4
Source File: BasePool.java From fresco with MIT License | 6 votes |
/** * Creates a new instance of the pool. * * @param poolParams pool parameters * @param poolStatsTracker */ public BasePool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker) { mMemoryTrimmableRegistry = Preconditions.checkNotNull(memoryTrimmableRegistry); mPoolParams = Preconditions.checkNotNull(poolParams); mPoolStatsTracker = Preconditions.checkNotNull(poolStatsTracker); // initialize the buckets mBuckets = new SparseArray<Bucket<V>>(); if (mPoolParams.fixBucketsReinitialization) { initBuckets(); } else { legacyInitBuckets(new SparseIntArray(0)); } mInUseValues = Sets.newIdentityHashSet(); mFree = new Counter(); mUsed = new Counter(); }
Example #5
Source File: SharedByteArray.java From fresco with MIT License | 6 votes |
public SharedByteArray(MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams params) { Preconditions.checkNotNull(memoryTrimmableRegistry); Preconditions.checkArgument(params.minBucketSize > 0); Preconditions.checkArgument(params.maxBucketSize >= params.minBucketSize); mMaxByteArraySize = params.maxBucketSize; mMinByteArraySize = params.minBucketSize; mByteArraySoftRef = new OOMSoftReference<byte[]>(); mSemaphore = new Semaphore(1); mResourceReleaser = new ResourceReleaser<byte[]>() { @Override public void release(byte[] unused) { mSemaphore.release(); } }; memoryTrimmableRegistry.registerMemoryTrimmable(this); }
Example #6
Source File: BitmapCountingMemoryCacheFactory.java From fresco with MIT License | 6 votes |
public static CountingMemoryCache<CacheKey, CloseableImage> get( Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier, MemoryTrimmableRegistry memoryTrimmableRegistry, CountingMemoryCache.CacheTrimStrategy trimStrategy, @Nullable CountingMemoryCache.EntryStateObserver<CacheKey> observer) { ValueDescriptor<CloseableImage> valueDescriptor = new ValueDescriptor<CloseableImage>() { @Override public int getSizeInBytes(CloseableImage value) { return value.getSizeInBytes(); } }; CountingMemoryCache<CacheKey, CloseableImage> countingCache = new CountingMemoryCache<>( valueDescriptor, trimStrategy, bitmapMemoryCacheParamsSupplier, observer); memoryTrimmableRegistry.registerMemoryTrimmable(countingCache); return countingCache; }
Example #7
Source File: BasePool.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
/** * Creates a new instance of the pool. * @param poolParams pool parameters * @param poolStatsTracker */ public BasePool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker) { mMemoryTrimmableRegistry = Preconditions.checkNotNull(memoryTrimmableRegistry); mPoolParams = Preconditions.checkNotNull(poolParams); mPoolStatsTracker = Preconditions.checkNotNull(poolStatsTracker); // initialize the buckets mBuckets = new SparseArray<Bucket<V>>(); initBuckets(new SparseIntArray(0)); mInUseValues = Sets.newIdentityHashSet(); mFree = new Counter(); mUsed = new Counter(); }
Example #8
Source File: BitmapPool.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
/** * Creates an instance of a bitmap pool. * @param memoryTrimmableRegistry the memory manager to register with * @param poolParams pool parameters */ public BitmapPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker) { super(memoryTrimmableRegistry, poolParams, poolStatsTracker); initialize(); }
Example #9
Source File: GenericByteArrayPoolTest.java From fresco with MIT License | 5 votes |
@Before public void setup() { final SparseIntArray bucketSizes = new SparseIntArray(); bucketSizes.put(32, 2); bucketSizes.put(64, 1); bucketSizes.put(128, 1); mPool = new GenericByteArrayPool( mock(MemoryTrimmableRegistry.class), new PoolParams(128, bucketSizes), mock(PoolStatsTracker.class)); }
Example #10
Source File: SingleByteArrayPool.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
/** * Creates an instance of the SingleByteArrayPool class, and registers it * @param memoryTrimmableRegistry the memory resource manager * @param singleByteArrayPoolStatsTracker stats tracker for the pool * @param params params for this pool */ public SingleByteArrayPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams params, SingleByteArrayPoolStatsTracker singleByteArrayPoolStatsTracker) { this( memoryTrimmableRegistry, singleByteArrayPoolStatsTracker, params.minBucketSize, params.maxBucketSize); }
Example #11
Source File: BasePoolTest.java From fresco with MIT License | 5 votes |
public TestPool(int maxPoolSizeSoftCap, int maxPoolSizeHardCap, SparseIntArray bucketSizes) { super( mock(MemoryTrimmableRegistry.class), new PoolParams(maxPoolSizeSoftCap, maxPoolSizeHardCap, bucketSizes), mock(PoolStatsTracker.class)); mIsReusable = true; initialize(); }
Example #12
Source File: SharedByteArrayTest.java From fresco with MIT License | 5 votes |
@Before public void setup() { mArray = new SharedByteArray( mock(MemoryTrimmableRegistry.class), new PoolParams(Integer.MAX_VALUE, Integer.MAX_VALUE, null, 4, 16, 1)); }
Example #13
Source File: BucketsBitmapPool.java From fresco with MIT License | 5 votes |
/** * Creates an instance of a bitmap pool. * * @param memoryTrimmableRegistry the memory manager to register with * @param poolParams pool parameters */ public BucketsBitmapPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker, boolean ignoreHardCap) { super(memoryTrimmableRegistry, poolParams, poolStatsTracker, ignoreHardCap); initialize(); }
Example #14
Source File: BasePool.java From fresco with MIT License | 5 votes |
public BasePool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker, boolean ignoreHardCap) { this(memoryTrimmableRegistry, poolParams, poolStatsTracker); mIgnoreHardCap = ignoreHardCap; }
Example #15
Source File: LruBitmapPool.java From fresco with MIT License | 5 votes |
public LruBitmapPool( int maxPoolSize, int maxBitmapSize, PoolStatsTracker poolStatsTracker, @Nullable MemoryTrimmableRegistry memoryTrimmableRegistry) { mMaxPoolSize = maxPoolSize; mMaxBitmapSize = maxBitmapSize; mPoolStatsTracker = poolStatsTracker; if (memoryTrimmableRegistry != null) { memoryTrimmableRegistry.registerMemoryTrimmable(this); } }
Example #16
Source File: GenericByteArrayPool.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
/** * Creates a new instance of the GenericByteArrayPool class * @param memoryTrimmableRegistry the memory manager to register with * @param poolParams provider for pool parameters * @param poolStatsTracker */ public GenericByteArrayPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker) { super(memoryTrimmableRegistry, poolParams, poolStatsTracker); final SparseIntArray bucketSizes = poolParams.bucketSizes; mBucketSizes = new int[bucketSizes.size()]; for (int i = 0; i < bucketSizes.size(); ++i) { mBucketSizes[i] = bucketSizes.keyAt(i); } initialize(); }
Example #17
Source File: GenericByteArrayPool.java From fresco with MIT License | 5 votes |
/** * Creates a new instance of the GenericByteArrayPool class * * @param memoryTrimmableRegistry the memory manager to register with * @param poolParams provider for pool parameters * @param poolStatsTracker */ public GenericByteArrayPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker) { super(memoryTrimmableRegistry, poolParams, poolStatsTracker); final SparseIntArray bucketSizes = poolParams.bucketSizes; mBucketSizes = new int[bucketSizes.size()]; for (int i = 0; i < bucketSizes.size(); ++i) { mBucketSizes[i] = bucketSizes.keyAt(i); } initialize(); }
Example #18
Source File: FlexByteArrayPool.java From fresco with MIT License | 5 votes |
public FlexByteArrayPool(MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams params) { Preconditions.checkArgument(params.maxNumThreads > 0); mDelegatePool = new SoftRefByteArrayPool( memoryTrimmableRegistry, params, NoOpPoolStatsTracker.getInstance()); mResourceReleaser = new ResourceReleaser<byte[]>() { @Override public void release(byte[] unused) { FlexByteArrayPool.this.release(unused); } }; }
Example #19
Source File: MemoryChunkPool.java From fresco with MIT License | 5 votes |
/** * Initialize a new instance of the MemoryChunkPool * * @param memoryTrimmableRegistry the memory manager to register with * @param poolParams provider for pool parameters * @param memoryChunkPoolStatsTracker the pool stats tracker */ MemoryChunkPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker memoryChunkPoolStatsTracker) { super(memoryTrimmableRegistry, poolParams, memoryChunkPoolStatsTracker); SparseIntArray bucketSizes = poolParams.bucketSizes; mBucketSizes = new int[bucketSizes.size()]; for (int i = 0; i < mBucketSizes.length; ++i) { mBucketSizes[i] = bucketSizes.keyAt(i); } initialize(); }
Example #20
Source File: BitmapCountingMemoryCacheFactory.java From fresco with MIT License | 5 votes |
public static CountingMemoryCache<CacheKey, CloseableImage> get( Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier, MemoryTrimmableRegistry memoryTrimmableRegistry, @Nullable CountingMemoryCache.EntryStateObserver<CacheKey> observer) { return get( bitmapMemoryCacheParamsSupplier, memoryTrimmableRegistry, new BitmapMemoryCacheTrimStrategy(), observer); }
Example #21
Source File: EncodedCountingMemoryCacheFactory.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
public static CountingMemoryCache<CacheKey, PooledByteBuffer, Void> get( Supplier<MemoryCacheParams> encodedMemoryCacheParamsSupplier, MemoryTrimmableRegistry memoryTrimmableRegistry) { MemoryCacheIndex<CacheKey, PooledByteBuffer, Void> memoryCacheIndex = new SimpleMemoryCacheIndex<CacheKey, PooledByteBuffer>(); CountingMemoryCache.ValueInfoCallback<PooledByteBuffer> valueTypeDescriptor = new CountingMemoryCache.ValueInfoCallback<PooledByteBuffer>() { @Override public long getSizeInBytes(PooledByteBuffer value) { return value.size(); } }; CountingMemoryCache.CacheTrimStrategy trimStrategy = new NativeMemoryCacheTrimStrategy(); CountingMemoryCache<CacheKey, PooledByteBuffer, Void> countingCache = new CountingMemoryCache<CacheKey, PooledByteBuffer, Void>( memoryCacheIndex, valueTypeDescriptor, trimStrategy, encodedMemoryCacheParamsSupplier); memoryTrimmableRegistry.registerMemoryTrimmable(countingCache); return countingCache; }
Example #22
Source File: BitmapCountingMemoryCacheFactory.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
public static CountingMemoryCache<BitmapMemoryCacheKey, CloseableImage, Void> get( Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier, MemoryTrimmableRegistry memoryTrimmableRegistry) { MemoryCacheIndex<BitmapMemoryCacheKey, CloseableImage, Void> memoryCacheIndex = new SimpleMemoryCacheIndex<BitmapMemoryCacheKey, CloseableImage>(); CountingMemoryCache.ValueInfoCallback<CloseableImage> valueTypeDescriptor = new CountingMemoryCache.ValueInfoCallback<CloseableImage>() { @Override public long getSizeInBytes(CloseableImage value) { return value.getSizeInBytes(); } }; CountingMemoryCache.CacheTrimStrategy trimStrategy = new BitmapMemoryCacheTrimStrategy(); CountingMemoryCache<BitmapMemoryCacheKey, CloseableImage, Void> countingCache = new CountingMemoryCache<BitmapMemoryCacheKey, CloseableImage, Void>( memoryCacheIndex, valueTypeDescriptor, trimStrategy, bitmapMemoryCacheParamsSupplier); memoryTrimmableRegistry.registerMemoryTrimmable(countingCache); return countingCache; }
Example #23
Source File: AshmemMemoryChunkPool.java From fresco with MIT License | 5 votes |
@DoNotStrip public AshmemMemoryChunkPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker ashmemMemoryChunkPoolStatsTracker) { super(memoryTrimmableRegistry, poolParams, ashmemMemoryChunkPoolStatsTracker); }
Example #24
Source File: NativeMemoryChunkPool.java From fresco with MIT License | 5 votes |
@DoNotStrip public NativeMemoryChunkPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker nativeMemoryChunkPoolStatsTracker) { super(memoryTrimmableRegistry, poolParams, nativeMemoryChunkPoolStatsTracker); }
Example #25
Source File: BufferMemoryChunkPool.java From fresco with MIT License | 5 votes |
@DoNotStrip public BufferMemoryChunkPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker bufferMemoryChunkPoolStatsTracker) { super(memoryTrimmableRegistry, poolParams, bufferMemoryChunkPoolStatsTracker); }
Example #26
Source File: NativeMemoryChunkPool.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
/** * Creates a new instance of the NativeMemoryChunkPool class * @param memoryTrimmableRegistry the memory manager to register with * @param poolParams provider for pool parameters * @param nativeMemoryChunkPoolStatsTracker */ public NativeMemoryChunkPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker nativeMemoryChunkPoolStatsTracker) { super(memoryTrimmableRegistry, poolParams, nativeMemoryChunkPoolStatsTracker); SparseIntArray bucketSizes = poolParams.bucketSizes; mBucketSizes = new int[bucketSizes.size()]; for (int i = 0; i < mBucketSizes.length; ++i) { mBucketSizes[i] = bucketSizes.keyAt(i); } initialize(); }
Example #27
Source File: FlexByteArrayPool.java From fresco with MIT License | 4 votes |
public SoftRefByteArrayPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker) { super(memoryTrimmableRegistry, poolParams, poolStatsTracker); }
Example #28
Source File: FakeNativeMemoryChunkPool.java From fresco with MIT License | 4 votes |
public FakeNativeMemoryChunkPool(PoolParams poolParams) { super(mock(MemoryTrimmableRegistry.class), poolParams, mock(PoolStatsTracker.class)); }
Example #29
Source File: FakeBufferMemoryChunkPool.java From fresco with MIT License | 4 votes |
public FakeBufferMemoryChunkPool(PoolParams poolParams) { super( Mockito.mock(MemoryTrimmableRegistry.class), poolParams, Mockito.mock(PoolStatsTracker.class)); }
Example #30
Source File: PoolConfig.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
public Builder setMemoryTrimmableRegistry(MemoryTrimmableRegistry memoryTrimmableRegistry) { mMemoryTrimmableRegistry = memoryTrimmableRegistry; return this; }