コード例 #1
0
        public static void PooledBufferWriterDefaultCapacity()
        {
            var allocator = MemoryPool <byte> .Shared.ToAllocator();

            using (var writer = new PooledBufferWriter <byte>(allocator))
                WriteReadUsingSpan(writer);
            using (var writer = new PooledBufferWriter <byte>(allocator))
                WriteReadUsingMemory(writer);
        }
コード例 #2
0
        public static void PooledBufferWriterWithCapacity()
        {
            var allocator = MemoryPool <byte> .Shared.ToAllocator();

            Throws <ArgumentOutOfRangeException>(new Action(() => new PooledBufferWriter <byte>(allocator, 0)));
            using (var writer = new PooledBufferWriter <byte>(allocator, 30))
                WriteReadUsingSpan(writer);
            using (var writer = new PooledBufferWriter <byte>(allocator, 20))
                WriteReadUsingMemory(writer);
        }
コード例 #3
0
        public static void ReuseMemoryWriter()
        {
            using var writer = new PooledBufferWriter <byte>(MemoryPool <byte> .Shared.ToAllocator());
            Equal(0, writer.Capacity);
            var span = writer.GetSpan(10);

            span[0] = 20;
            span[9] = 30;
            writer.Advance(10);
            writer.Clear();

            span    = writer.GetSpan(10);
            span[0] = 40;
            span[9] = 50;
            writer.Advance(10);

            Equal(40, writer.WrittenMemory.Span[0]);
            Equal(50, writer.WrittenMemory.Span[9]);
        }
コード例 #4
0
 public static void ReadWriteUsingPooledBufferWriter()
 {
     using var writer = new PooledBufferWriter <byte>(null);
     Null(writer.As <IGrowableBuffer <byte> >().Capacity);
     ReadWriteTest(writer);
 }