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); }
/** * 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(); }
@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; }
public static CountingMemoryCache<CacheKey, CloseableImage> get( Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier, MemoryTrimmableRegistry memoryTrimmableRegistry, PlatformBitmapFactory platformBitmapFactory, boolean isExternalCreatedBitmapLogEnabled) { return get( bitmapMemoryCacheParamsSupplier, memoryTrimmableRegistry, platformBitmapFactory, isExternalCreatedBitmapLogEnabled, new BitmapMemoryCacheTrimStrategy()); }
public static CountingMemoryCache<CacheKey, CloseableImage> get( Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier, MemoryTrimmableRegistry memoryTrimmableRegistry, PlatformBitmapFactory platformBitmapFactory, boolean isExternalCreatedBitmapLogEnabled, CountingMemoryCache.CacheTrimStrategy trimStrategy) { ValueDescriptor<CloseableImage> valueDescriptor = new ValueDescriptor<CloseableImage>() { @Override public int getSizeInBytes(CloseableImage value) { return value.getSizeInBytes(); } }; CountingMemoryCache<CacheKey, CloseableImage> countingCache = new CountingMemoryCache<>( valueDescriptor, trimStrategy, bitmapMemoryCacheParamsSupplier, platformBitmapFactory, isExternalCreatedBitmapLogEnabled); memoryTrimmableRegistry.registerMemoryTrimmable(countingCache); return countingCache; }
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); } }; }
/** * 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(); }
/** * 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(); }
/** * 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(); }
public static CountingMemoryCache<CacheKey, PooledByteBuffer> get( Supplier<MemoryCacheParams> encodedMemoryCacheParamsSupplier, MemoryTrimmableRegistry memoryTrimmableRegistry, PlatformBitmapFactory platformBitmapFactory) { 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, platformBitmapFactory, false); memoryTrimmableRegistry.registerMemoryTrimmable(countingCache); return countingCache; }
@Before public void setup() { mArray = new SharedByteArray( mock(MemoryTrimmableRegistry.class), new PoolParams( Integer.MAX_VALUE, Integer.MAX_VALUE, null, 4, 16, 1)); }
public TestPool( int maxPoolSizeSoftCap, int maxPoolSizeHardCap, SparseIntArray bucketSizes) { super( mock(MemoryTrimmableRegistry.class), new PoolParams(maxPoolSizeSoftCap, maxPoolSizeHardCap, bucketSizes), mock(PoolStatsTracker.class)); mIsReusable = true; initialize(); }
@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)); }
public MemoryTrimmableRegistry getMemoryTrimmableRegistry() { return mMemoryTrimmableRegistry; }
public Builder setMemoryTrimmableRegistry(MemoryTrimmableRegistry memoryTrimmableRegistry) { mMemoryTrimmableRegistry = memoryTrimmableRegistry; return this; }
public SoftRefByteArrayPool( MemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker) { super(memoryTrimmableRegistry, poolParams, poolStatsTracker); }
public FakeNativeMemoryChunkPool(PoolParams poolParams) { super( mock(MemoryTrimmableRegistry.class), poolParams, mock(PoolStatsTracker.class)); }