public void Write(TorrentFile file, long offset, byte[] buffer, int bufferOffset, int count, bool forceWrite) { if (forceWrite) { Writer.Write(file, offset, buffer, bufferOffset, count); } else { if (CacheUsed > (Capacity - count)) { Flush(0); } byte[] cacheBuffer = ClientEngine.BufferManager.GetBuffer(count); Buffer.BlockCopy(buffer, bufferOffset, cacheBuffer, 0, count); CachedBlock block = new CachedBlock(); block.Buffer = cacheBuffer; block.Count = count; block.Offset = offset; block.File = file; CachedBlocks.Add(block); Interlocked.Add(ref cacheUsed, block.Count); } }
public async ReusableTask WriteAsync(ITorrentFileInfo file, long offset, byte[] buffer, int bufferOffset, int count, bool forceWrite) { if (forceWrite) { await Writer.WriteAsync(file, offset, buffer, bufferOffset, count); } else { if (CacheUsed > (Capacity - count)) { await FlushAsync(0); } var releaser = DiskManager.BufferPool.Rent(count, out byte[] cacheBuffer); Buffer.BlockCopy(buffer, bufferOffset, cacheBuffer, 0, count); var block = new CachedBlock { Buffer = cacheBuffer, BufferReleaser = releaser, Count = count, Offset = offset, File = file }; CachedBlocks.Add(block); Interlocked.Add(ref cacheUsed, block.Count); } }
public void Write(TorrentFile file, long offset, byte[] buffer, int bufferOffset, int count, bool forceWrite) { if (forceWrite) { Writer.Write(file, offset, buffer, bufferOffset, count); } else { if (CacheUsed > (Capacity - count)) { Flush(0); } var releaser = ClientEngine.BufferPool.Rent(count, out byte[] cacheBuffer); Buffer.BlockCopy(buffer, bufferOffset, cacheBuffer, 0, count); var block = new CachedBlock { Buffer = cacheBuffer, BufferReleaser = releaser, Count = count, Offset = offset, File = file }; CachedBlocks.Add(block); Interlocked.Add(ref cacheUsed, block.Count); } }