예제 #1
0
        public unsafe static void MemoryOfChar8_WithUtf8String_Pin()
        {
            Utf8String             theString = u8("Hello");
            ReadOnlyMemory <Char8> rom       = theString.AsMemory();
            MemoryHandle           memHandle = default;

            try
            {
                memHandle = Unsafe.As <ReadOnlyMemory <Char8>, Memory <Char8> >(ref rom).Pin();
                Assert.True(memHandle.Pointer == Unsafe.AsPointer(ref Unsafe.AsRef(in theString.GetPinnableReference())));
            }
            finally
            {
                memHandle.Dispose();
            }
        }
예제 #2
0
        public void AsMemory_FromUtf8String()
        {
            Assert.True(default(ReadOnlyMemory <Char8>).Equals(((Utf8String)null).AsMemory()));

            Utf8String theString = u8("Hello");

            Assert.True(MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As <byte, Char8>(ref Unsafe.AsRef(in theString.GetPinnableReference())), 5) == theString.AsMemory().Span);
        }
예제 #3
0
        public void AsBytes_FromSpan_Default_netcoreapp()
        {
            // a span wrapping data should become a span wrapping that same data.

            Utf8String theString = u8("Hello");

            Assert.True(MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AsRef(in theString.GetPinnableReference()), 5) == (theString.AsMemory().Span).AsBytes());
        }
예제 #4
0
        public unsafe void AsBytes_FromSpan_Default()
        {
            // First, a default span should become a default span.

            Assert.True(default(ReadOnlySpan <byte>) == new ReadOnlySpan <Char8>().AsBytes());

            // Next, an empty but non-default span should become an empty but non-default span.

            Assert.True(new ReadOnlySpan <byte>((void *)0x12345, 0) == new ReadOnlySpan <Char8>((void *)0x12345, 0).AsBytes());

            // Finally, a span wrapping data should become a span wrapping that same data.

            Utf8String theString = u8("Hello");

            Assert.True(MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AsRef(in theString.GetPinnableReference()), 5) == (theString.AsMemory().Span).AsBytes());
        }