示例#1
0
        public unsafe void External()
        {
            var array = new byte[] { 1, 2, 3, 4 };

            fixed(byte *arrayPtr = array)
            {
                using (var provider = new ExternalMemoryBlockProvider(arrayPtr, array.Length))
                {
                    using (var block = provider.GetMemoryBlock())
                    {
                        Assert.Equal(4, block.Size);
                        AssertEx.Equal(provider.Pointer, block.Pointer);
                        AssertEx.Equal(new byte[] { }, block.GetContentUnchecked(0, 0));
                        AssertEx.Equal(new byte[] { 3, 4 }, block.GetContentUnchecked(2, 2));
                        AssertEx.Equal(new byte[] { 1, 2, 3 }, block.GetContentUnchecked(0, 3));
                    }

                    using (var block = provider.GetMemoryBlock(1, 2))
                    {
                        AssertEx.Equal(provider.Pointer + 1, block.Pointer);
                        Assert.Equal(2, block.Size);
                        AssertEx.Equal(new byte[] { 2, 3 }, block.GetContentUnchecked(0, 2));
                        AssertEx.Equal(new byte[] { 3 }, block.GetContentUnchecked(1, 1));
                        AssertEx.Equal(new byte[] { }, block.GetContentUnchecked(2, 0));
                    }
                }
            }
        }
        public unsafe void External()
        {
            var array = new byte[] { 1, 2, 3, 4 };
            fixed (byte* arrayPtr = array)
            {
                using (var provider = new ExternalMemoryBlockProvider(arrayPtr, array.Length))
                {
                    using (var block = provider.GetMemoryBlock())
                    {
                        Assert.Equal(4, block.Size);
                        AssertEx.Equal(provider.Pointer, block.Pointer);
                        AssertEx.Equal(new byte[] { }, block.GetContentUnchecked(0, 0));
                        AssertEx.Equal(new byte[] { 3, 4 }, block.GetContentUnchecked(2, 2));
                        AssertEx.Equal(new byte[] { 1, 2, 3 }, block.GetContentUnchecked(0, 3));
                    }

                    using (var block = provider.GetMemoryBlock(1, 2))
                    {
                        AssertEx.Equal(provider.Pointer + 1, block.Pointer);
                        Assert.Equal(2, block.Size);
                        AssertEx.Equal(new byte[] { 2, 3 }, block.GetContentUnchecked(0, 2));
                        AssertEx.Equal(new byte[] { 3 }, block.GetContentUnchecked(1, 1));
                        AssertEx.Equal(new byte[] { }, block.GetContentUnchecked(2, 0));
                    }
                }
            }
        }