v7.3.2018.0614   重构高性能资源池,减少GC压力,增加线程池,让异步任务得到平等竞争CPU的机会
大石头 authored at 2018-06-14 17:56:44
987.00 B
X
using System.IO;

namespace NewLife.Queue.Storage
{
    internal class WriterWorkItem
    {
        public readonly MemoryStream BufferStream;
        public readonly BinaryWriter BufferWriter;
        public readonly IStream WorkingStream;
        public long LastFlushedPosition;

        public WriterWorkItem(IStream stream)
        {
            WorkingStream = stream;
            BufferStream = new MemoryStream(8192);
            BufferWriter = new BinaryWriter(BufferStream);
        }

        public void AppendData(byte[] buf, int offset, int len)
        {
            WorkingStream.Write(buf, offset, len);
        }
        public void FlushToDisk()
        {
            WorkingStream.Flush();
            LastFlushedPosition = WorkingStream.Position;
        }
        public void ResizeStream(long length)
        {
            WorkingStream.SetLength(length);
        }
        public void Dispose()
        {
            WorkingStream.Dispose();
        }
    }
}