static int Free(MemoryRegionCache cache) { if (cache is null) { return(0); } return(cache.Free()); }
/// <summary> /// Add <see cref="PoolChunk{T}"/> and <paramref name="handle"/> to the cache if there is enough room. /// </summary> /// <returns><c>true</c> if it fit into the cache <c>false</c> otherwise.</returns> internal bool Add(PoolArena <T> area, PoolChunk <T> chunk, long handle, int normCapacity, SizeClass sizeClass) { MemoryRegionCache cache = Cache(area, normCapacity, sizeClass); if (cache is null) { return(false); } return(cache.Add(chunk, handle)); }
bool Allocate(MemoryRegionCache cache, PooledByteBuffer <T> buf, int reqCapacity) { if (cache is null) { // no cache found so just return false here return(false); } bool allocated = cache.Allocate(buf, reqCapacity, this); if (++_allocations >= _freeSweepAllocationThreshold) { _allocations = 0; Trim(); } return(allocated); }
bool Allocate(MemoryRegionCache cache, PooledArrayBuffer <T> buf, int reqCapacity) { if (cache == null) { // no cache found so just return false here return(false); } bool allocated = cache.Allocate(buf, reqCapacity); if (++this.allocations >= this.freeSweepAllocationThreshold) { this.allocations = 0; this.Trim(); } return(allocated); }
static MemoryRegionCache[] CreateSubPageCaches( int cacheSize, int numCaches, SizeClass sizeClass) { if (cacheSize > 0) { var cache = new MemoryRegionCache[numCaches]; for (int i = 0; i < cache.Length; i++) { cache[i] = new SubPageMemoryRegionCache(cacheSize, sizeClass); } return(cache); } else { return(null); } }
static MemoryRegionCache[] CreateNormalCaches( int cacheSize, int maxCachedBufferCapacity, PoolArena <T> area) { if (cacheSize > 0 && maxCachedBufferCapacity > 0) { int max = Math.Min(area.ChunkSize, maxCachedBufferCapacity); int arraySize = Math.Max(1, Log2(max / area.PageSize) + 1); var cache = new MemoryRegionCache[arraySize]; for (int i = 0; i < cache.Length; i++) { cache[i] = new NormalMemoryRegionCache(cacheSize); } return(cache); } else { return(null); } }
static void Trim(MemoryRegionCache cache) => cache?.Trim();
static int Free(MemoryRegionCache cache) => cache?.Free() ?? 0;
/// // Add {@link PoolChunk} and {@code handle} to the cache if there is enough room. // Returns {@code true} if it fit into the cache {@code false} otherwise. // internal bool Add(PoolArena <T> area, PoolChunk <T> chunk, long handle, int normCapacity, SizeClass sizeClass) { MemoryRegionCache c = this.Cache(normCapacity, sizeClass); return(c != null && c.Add(chunk, handle)); }