/// <summary> /// Returns the encoded <see cref="CountingMemoryCache{K, V}"/>. /// </summary> public static CountingMemoryCache <ICacheKey, IPooledByteBuffer> Get( ISupplier <MemoryCacheParams> encodedMemoryCacheParamsSupplier, IMemoryTrimmableRegistry memoryTrimmableRegistry, PlatformBitmapFactory platformBitmapFactory) { IValueDescriptor <IPooledByteBuffer> valueDescriptor = new ValueDescriptorImpl <IPooledByteBuffer>( (value) => { return(value.Size); }); ICacheTrimStrategy trimStrategy = new NativeMemoryCacheTrimStrategy(); CountingMemoryCache <ICacheKey, IPooledByteBuffer> countingCache = new CountingMemoryCache <ICacheKey, IPooledByteBuffer>( valueDescriptor, trimStrategy, encodedMemoryCacheParamsSupplier, platformBitmapFactory, false); memoryTrimmableRegistry.RegisterMemoryTrimmable(countingCache); return(countingCache); }
/// <summary> /// Instantiates the bitmap counting memory cache. /// </summary> public static CountingMemoryCache <ICacheKey, CloseableImage> Get( ISupplier <MemoryCacheParams> bitmapMemoryCacheParamsSupplier, IMemoryTrimmableRegistry memoryTrimmableRegistry, PlatformBitmapFactory platformBitmapFactory, bool isExternalCreatedBitmapLogEnabled) { IValueDescriptor <CloseableImage> valueDescriptor = new ValueDescriptorImpl <CloseableImage>( (value) => { return(value.SizeInBytes); }); ICacheTrimStrategy trimStrategy = new BitmapMemoryCacheTrimStrategy(); CountingMemoryCache <ICacheKey, CloseableImage> countingCache = new CountingMemoryCache <ICacheKey, CloseableImage>( valueDescriptor, trimStrategy, bitmapMemoryCacheParamsSupplier, platformBitmapFactory, isExternalCreatedBitmapLogEnabled); memoryTrimmableRegistry.RegisterMemoryTrimmable(countingCache); return(countingCache); }
public SoftRefByteArrayPool( IMemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker) : base(memoryTrimmableRegistry, poolParams, poolStatsTracker) { }
/// <summary> /// Instantiates the <see cref="FlexByteArrayPool"/>. /// </summary> /// <param name="memoryTrimmableRegistry"> /// A class to be notified of system memory events. /// </param> /// <param name="args">The pool params.</param> public FlexByteArrayPool( IMemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams args) { Preconditions.CheckArgument(args.MaxNumThreads > 0); _delegatePool = new SoftRefByteArrayPool( memoryTrimmableRegistry, args, NoOpPoolStatsTracker.Instance); _resourceReleaser = new ResourceReleaserImpl <byte[]>(value => Release(value)); }
/// <summary> /// Creates an instance of a bitmap pool. /// </summary> /// <param name="memoryTrimmableRegistry"> /// The memory manager to register with. /// </param> /// <param name="poolParams">Pool parameters.</param> /// <param name="poolStatsTracker"> /// Listener that logs pool statistics. /// </param> public BitmapPool( IMemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker) : base( memoryTrimmableRegistry, poolParams, poolStatsTracker) { Initialize(); }
/// <summary> /// Creates a new instance of the GenericByteArrayPool class. /// </summary> /// <param name="memoryTrimmableRegistry"> /// The memory manager to register with. /// </param> /// <param name="poolParams"> /// Provider for pool parameters. /// </param> /// <param name="poolStatsTracker"> /// Listener that logs pool statistics. /// </param> public GenericByteArrayPool( IMemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker) : base(memoryTrimmableRegistry, poolParams, poolStatsTracker) { _bucketSizes = new int[poolParams.BucketSizes.Keys.Count]; poolParams.BucketSizes.Keys.CopyTo(_bucketSizes, 0); Initialize(); }
private ImagePipelineConfig(Builder builder) { _animatedImageFactory = builder.AnimatedImageFactory; _bitmapMemoryCacheParamsSupplier = builder.BitmapMemoryCacheParamsSupplier ?? new DefaultBitmapMemoryCacheParamsSupplier(); _bitmapConfig = builder.BitmapConfig == default(BitmapPixelFormat) ? BitmapPixelFormat.Bgra8 : builder.BitmapConfig; _cacheKeyFactory = builder.CacheKeyFactory ?? DefaultCacheKeyFactory.Instance; _decodeMemoryFileEnabled = builder.IsDecodeMemoryFileEnabled; _fileCacheFactory = builder.FileCacheFactory ?? new DiskStorageCacheFactory(new DynamicDefaultDiskStorageFactory()); _downsampleEnabled = builder.IsDownsampleEnabled; _encodedMemoryCacheParamsSupplier = builder.EncodedMemoryCacheParamsSupplier ?? new DefaultEncodedMemoryCacheParamsSupplier(); _imageCacheStatsTracker = builder.ImageCacheStatsTracker ?? NoOpImageCacheStatsTracker.Instance; _imageDecoder = builder.ImageDecoder; _isPrefetchEnabledSupplier = builder.IsPrefetchEnabledSupplier ?? new SupplierImpl <bool>( () => { return(true); }); _mainDiskCacheConfig = builder.MainDiskCacheConfig ?? GetDefaultMainDiskCacheConfig(); _memoryTrimmableRegistry = builder.MemoryTrimmableRegistry ?? NoOpMemoryTrimmableRegistry.Instance; _networkFetcher = builder.NetworkFetcher ?? new HttpUrlConnectionNetworkFetcher(); _platformBitmapFactory = builder.PlatformBitmapFactory; _poolFactory = builder.PoolFactory ?? new PoolFactory(PoolConfig.NewBuilder().Build()); _progressiveJpegConfig = builder.ProgressiveJpegConfig == default(IProgressiveJpegConfig) ? new SimpleProgressiveJpegConfig() : builder.ProgressiveJpegConfig; _requestListeners = builder.RequestListeners ?? new HashSet <IRequestListener>(); _resizeAndRotateEnabledForNetwork = builder.ResizeAndRotateEnabledForNetwork; _smallImageDiskCacheConfig = builder.SmallImageDiskCacheConfig ?? _mainDiskCacheConfig; // Below this comment can't be built in alphabetical order, because of dependencies int numCpuBoundThreads = _poolFactory.FlexByteArrayPoolMaxNumThreads; _executorSupplier = builder.ExecutorSupplier ?? new DefaultExecutorSupplier(numCpuBoundThreads); _imagePipelineExperiments = builder.Experiment.Build(); }
/// <summary> /// Creates a new instance of <see cref="NativeMemoryChunkPool"/>. /// </summary> /// <param name="memoryTrimmableRegistry"> /// The memory manager to register with. /// </param> /// <param name="poolParams"> /// Provider for pool parameters. /// </param> /// <param name="nativeMemoryChunkPoolStatsTracker"> /// The pool stats tracker. /// </param> public NativeMemoryChunkPool( IMemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker nativeMemoryChunkPoolStatsTracker) : base( memoryTrimmableRegistry, poolParams, nativeMemoryChunkPoolStatsTracker) { Dictionary <int, int> bucketSizes = poolParams.BucketSizes; _bucketSizes = new int[bucketSizes.Keys.Count]; poolParams.BucketSizes.Keys.CopyTo(_bucketSizes, 0); Initialize(); }
/// <summary> /// Instantiates the <see cref="SharedByteArray"/>. /// </summary> /// <param name="memoryTrimmableRegistry"> /// A class to be notifiedof system memory events. /// </param> /// <param name="args">The pool params.</param> public SharedByteArray( IMemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams args) { Preconditions.CheckNotNull(memoryTrimmableRegistry); Preconditions.CheckArgument(args.MinBucketSize > 0); Preconditions.CheckArgument(args.MaxBucketSize >= args.MinBucketSize); _maxByteArraySize = args.MaxBucketSize; _minByteArraySize = args.MinBucketSize; _byteArraySoftRef = new OOMSoftReference <byte[]>(); _resourceReleaser = new ResourceReleaserImpl <byte[]>(value => { _semaphore.Release(); }); memoryTrimmableRegistry.RegisterMemoryTrimmable(this); }
/// <summary> /// Creates a new instance of the pool. /// </summary> /// <param name="memoryTrimmableRegistry"> /// A class to be notified of system memory events. /// </param> /// <param name="poolParams">Pool parameters.</param> /// <param name="poolStatsTracker"> /// Listener that logs pool statistics. /// </param> public BasePool( IMemoryTrimmableRegistry memoryTrimmableRegistry, PoolParams poolParams, PoolStatsTracker poolStatsTracker) { _memoryTrimmableRegistry = Preconditions.CheckNotNull(memoryTrimmableRegistry); _poolParams = Preconditions.CheckNotNull(poolParams); _poolStatsTracker = Preconditions.CheckNotNull(poolStatsTracker); // Initialize the buckets Buckets = new Dictionary <int, Bucket <T> >(); InitBuckets(new Dictionary <int, int>(0)); InUseValues = new HashSet <T>(); _freeCounter = new Counter(); _usedCounter = new Counter(); }
/// <summary> /// Sets the <see cref="IMemoryTrimmableRegistry"/>. /// </summary> public Builder SetMemoryTrimmableRegistry( IMemoryTrimmableRegistry memoryTrimmableRegistry) { _memoryTrimmableRegistry = memoryTrimmableRegistry; return(this); }