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(); } }
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); }
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()); }
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()); }