{
Debug.Assert(array != null, "Array can't be null");
- int len = array.Length;
- // Handle 0 length byte arrays specially.
- if (len == 0)
- {
- array = new byte[1];
- len = 0;
- }
-
_array = array;
_pinningHandle = GCHandle.Alloc(array, GCHandleType.Pinned);
// Now the byte[] is pinned for the lifetime of this instance.
// But I also need to get a pointer to that block of memory...
- fixed (byte* ptr = &_array[0])
+ int len = array.Length;
+ fixed (byte* ptr = &MemoryMarshal.GetReference((Span<byte>)array))
Initialize(ptr, len, len, FileAccess.Read);
}
static internal char ConvertToManaged(byte nativeChar)
{
- byte[] bytes = new byte[1] { nativeChar };
+ Span<byte> bytes = new Span<byte>(ref nativeChar, 1);
string str = Encoding.Default.GetString(bytes);
return str[0];
}