Java 类com.facebook.common.memory.MemoryTrimmableRegistry 实例源码

项目:GitHub    文件:SharedByteArray.java   
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);
}
项目:GitHub    文件:BasePool.java   
/**
 * 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();
}
项目:GitHub    文件:FlexByteArrayPoolTest.java   
@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;
}
项目:fresco    文件:SharedByteArray.java   
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);
}
项目:fresco    文件:BasePool.java   
/**
 * 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();
}
项目:fresco    文件:FlexByteArrayPoolTest.java   
@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;
}
项目:GitHub    文件:BitmapCountingMemoryCacheFactory.java   
public static CountingMemoryCache<CacheKey, CloseableImage> get(
        Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier,
        MemoryTrimmableRegistry memoryTrimmableRegistry,
        PlatformBitmapFactory platformBitmapFactory,
        boolean isExternalCreatedBitmapLogEnabled) {
  return get(
          bitmapMemoryCacheParamsSupplier,
          memoryTrimmableRegistry,
          platformBitmapFactory,
          isExternalCreatedBitmapLogEnabled,
          new BitmapMemoryCacheTrimStrategy());
}
项目:GitHub    文件:BitmapCountingMemoryCacheFactory.java   
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;
}
项目:GitHub    文件:FlexByteArrayPool.java   
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);
    }
  };
}
项目:GitHub    文件:GenericByteArrayPool.java   
/**
 * 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();
}
项目:GitHub    文件:NativeMemoryChunkPool.java   
/**
 * 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();
}
项目:GitHub    文件:BitmapPool.java   
/**
 * 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();
}
项目:GitHub    文件:EncodedCountingMemoryCacheFactory.java   
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;
}
项目:GitHub    文件:SharedByteArrayTest.java   
@Before
public void setup() {
  mArray = new SharedByteArray(
      mock(MemoryTrimmableRegistry.class),
      new PoolParams(
          Integer.MAX_VALUE,
          Integer.MAX_VALUE,
          null,
          4,
          16,
          1));
}
项目:GitHub    文件:BasePoolTest.java   
public TestPool(
    int maxPoolSizeSoftCap,
    int maxPoolSizeHardCap,
    SparseIntArray bucketSizes) {
  super(
      mock(MemoryTrimmableRegistry.class),
      new PoolParams(maxPoolSizeSoftCap, maxPoolSizeHardCap, bucketSizes),
      mock(PoolStatsTracker.class));
  mIsReusable = true;
  initialize();
}
项目:GitHub    文件:GenericByteArrayPoolTest.java   
@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));
}
项目:fresco    文件:BitmapCountingMemoryCacheFactory.java   
public static CountingMemoryCache<CacheKey, CloseableImage> get(
        Supplier<MemoryCacheParams> bitmapMemoryCacheParamsSupplier,
        MemoryTrimmableRegistry memoryTrimmableRegistry,
        PlatformBitmapFactory platformBitmapFactory,
        boolean isExternalCreatedBitmapLogEnabled) {
  return get(
          bitmapMemoryCacheParamsSupplier,
          memoryTrimmableRegistry,
          platformBitmapFactory,
          isExternalCreatedBitmapLogEnabled,
          new BitmapMemoryCacheTrimStrategy());
}
项目:fresco    文件:BitmapCountingMemoryCacheFactory.java   
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;
}
项目:fresco    文件:FlexByteArrayPool.java   
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);
    }
  };
}
项目:fresco    文件:GenericByteArrayPool.java   
/**
 * 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();
}
项目:fresco    文件:NativeMemoryChunkPool.java   
/**
 * 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();
}
项目:fresco    文件:BitmapPool.java   
/**
 * 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();
}
项目:fresco    文件:EncodedCountingMemoryCacheFactory.java   
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;
}
项目:fresco    文件:SharedByteArrayTest.java   
@Before
public void setup() {
  mArray = new SharedByteArray(
      mock(MemoryTrimmableRegistry.class),
      new PoolParams(
          Integer.MAX_VALUE,
          Integer.MAX_VALUE,
          null,
          4,
          16,
          1));
}
项目:fresco    文件:BasePoolTest.java   
public TestPool(
    int maxPoolSizeSoftCap,
    int maxPoolSizeHardCap,
    SparseIntArray bucketSizes) {
  super(
      mock(MemoryTrimmableRegistry.class),
      new PoolParams(maxPoolSizeSoftCap, maxPoolSizeHardCap, bucketSizes),
      mock(PoolStatsTracker.class));
  mIsReusable = true;
  initialize();
}
项目:fresco    文件:GenericByteArrayPoolTest.java   
@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));
}
项目:GitHub    文件:PoolConfig.java   
public MemoryTrimmableRegistry getMemoryTrimmableRegistry() {
  return mMemoryTrimmableRegistry;
}
项目:GitHub    文件:PoolConfig.java   
public Builder setMemoryTrimmableRegistry(MemoryTrimmableRegistry memoryTrimmableRegistry) {
  mMemoryTrimmableRegistry = memoryTrimmableRegistry;
  return this;
}
项目:GitHub    文件:FlexByteArrayPool.java   
public SoftRefByteArrayPool(
    MemoryTrimmableRegistry memoryTrimmableRegistry,
    PoolParams poolParams,
    PoolStatsTracker poolStatsTracker) {
  super(memoryTrimmableRegistry, poolParams, poolStatsTracker);
}
项目:GitHub    文件:ImagePipelineConfig.java   
public MemoryTrimmableRegistry getMemoryTrimmableRegistry() {
  return mMemoryTrimmableRegistry;
}
项目:GitHub    文件:ImagePipelineConfig.java   
public Builder setMemoryTrimmableRegistry(MemoryTrimmableRegistry memoryTrimmableRegistry) {
  mMemoryTrimmableRegistry = memoryTrimmableRegistry;
  return this;
}
项目:GitHub    文件:FakeNativeMemoryChunkPool.java   
public FakeNativeMemoryChunkPool(PoolParams poolParams) {
  super(
      mock(MemoryTrimmableRegistry.class),
      poolParams,
      mock(PoolStatsTracker.class));
}
项目:fresco    文件:PoolConfig.java   
public MemoryTrimmableRegistry getMemoryTrimmableRegistry() {
  return mMemoryTrimmableRegistry;
}
项目:fresco    文件:PoolConfig.java   
public Builder setMemoryTrimmableRegistry(MemoryTrimmableRegistry memoryTrimmableRegistry) {
  mMemoryTrimmableRegistry = memoryTrimmableRegistry;
  return this;
}
项目:fresco    文件:FlexByteArrayPool.java   
public SoftRefByteArrayPool(
    MemoryTrimmableRegistry memoryTrimmableRegistry,
    PoolParams poolParams,
    PoolStatsTracker poolStatsTracker) {
  super(memoryTrimmableRegistry, poolParams, poolStatsTracker);
}
项目:fresco    文件:ImagePipelineConfig.java   
public MemoryTrimmableRegistry getMemoryTrimmableRegistry() {
  return mMemoryTrimmableRegistry;
}
项目:fresco    文件:ImagePipelineConfig.java   
public Builder setMemoryTrimmableRegistry(MemoryTrimmableRegistry memoryTrimmableRegistry) {
  mMemoryTrimmableRegistry = memoryTrimmableRegistry;
  return this;
}
项目:fresco    文件:FakeNativeMemoryChunkPool.java   
public FakeNativeMemoryChunkPool(PoolParams poolParams) {
  super(
      mock(MemoryTrimmableRegistry.class),
      poolParams,
      mock(PoolStatsTracker.class));
}