using System.Diagnostics;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
using Internal.Runtime.CompilerServices;
namespace System
if (destination.Length < sizeof(byte))
return false;
- Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value ? (byte)1 : (byte)0);
+ Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value ? (byte)1 : (byte)0);
return true;
}
if (destination.Length < sizeof(char))
return false;
- Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value);
+ Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
return true;
}
if (destination.Length < sizeof(short))
return false;
- Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value);
+ Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
return true;
}
if (destination.Length < sizeof(int))
return false;
- Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value);
+ Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
return true;
}
if (destination.Length < sizeof(long))
return false;
- Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value);
+ Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
return true;
}
if (destination.Length < sizeof(ushort))
return false;
- Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value);
+ Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
return true;
}
if (destination.Length < sizeof(uint))
return false;
- Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value);
+ Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
return true;
}
if (destination.Length < sizeof(ulong))
return false;
- Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value);
+ Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
return true;
}
if (destination.Length < sizeof(float))
return false;
- Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value);
+ Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
return true;
}
if (destination.Length < sizeof(double))
return false;
- Unsafe.WriteUnaligned(ref destination.DangerousGetPinnableReference(), value);
+ Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(destination), value);
return true;
}
{
if (value.Length < sizeof(char))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<char>(ref value.DangerousGetPinnableReference());
+ return Unsafe.ReadUnaligned<char>(ref MemoryMarshal.GetReference(value));
}
// Converts an array of bytes into a short.
{
if (value.Length < sizeof(short))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<short>(ref value.DangerousGetPinnableReference());
+ return Unsafe.ReadUnaligned<short>(ref MemoryMarshal.GetReference(value));
}
// Converts an array of bytes into an int.
{
if (value.Length < sizeof(int))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<int>(ref value.DangerousGetPinnableReference());
+ return Unsafe.ReadUnaligned<int>(ref MemoryMarshal.GetReference(value));
}
// Converts an array of bytes into a long.
{
if (value.Length < sizeof(long))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<long>(ref value.DangerousGetPinnableReference());
+ return Unsafe.ReadUnaligned<long>(ref MemoryMarshal.GetReference(value));
}
// Converts an array of bytes into an ushort.
{
if (value.Length < sizeof(ushort))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<ushort>(ref value.DangerousGetPinnableReference());
+ return Unsafe.ReadUnaligned<ushort>(ref MemoryMarshal.GetReference(value));
}
// Converts an array of bytes into an uint.
{
if (value.Length < sizeof(uint))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<uint>(ref value.DangerousGetPinnableReference());
+ return Unsafe.ReadUnaligned<uint>(ref MemoryMarshal.GetReference(value));
}
// Converts an array of bytes into an unsigned long.
{
if (value.Length < sizeof(ulong))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<ulong>(ref value.DangerousGetPinnableReference());
+ return Unsafe.ReadUnaligned<ulong>(ref MemoryMarshal.GetReference(value));
}
// Converts an array of bytes into a float.
{
if (value.Length < sizeof(float))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<float>(ref value.DangerousGetPinnableReference());
+ return Unsafe.ReadUnaligned<float>(ref MemoryMarshal.GetReference(value));
}
// Converts an array of bytes into a double.
{
if (value.Length < sizeof(double))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<double>(ref value.DangerousGetPinnableReference());
+ return Unsafe.ReadUnaligned<double>(ref MemoryMarshal.GetReference(value));
}
// Converts an array of bytes into a String.
{
if (value.Length < sizeof(byte))
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value);
- return Unsafe.ReadUnaligned<byte>(ref value.DangerousGetPinnableReference()) != 0;
+ return Unsafe.ReadUnaligned<byte>(ref MemoryMarshal.GetReference(value)) != 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe
{
- fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference())
+ fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
fixed (char* charsPtr = result)
{
int charsWritten = ConvertToBase64Array(charsPtr, bytesPtr, 0, bytes.Length, insertLineBreaks);
return false;
}
- fixed (char* outChars = &chars.DangerousGetPinnableReference())
- fixed (byte* inData = &bytes.DangerousGetPinnableReference())
+ fixed (char* outChars = &MemoryMarshal.GetReference(chars))
+ fixed (byte* inData = &MemoryMarshal.GetReference(bytes))
{
charsWritten = ConvertToBase64Array(outChars, inData, 0, bytes.Length, insertLineBreaks);
return true;
chars = chars.Slice(0, chars.Length - 1);
}
- fixed (char* charsPtr = &chars.DangerousGetPinnableReference())
+ fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
{
int resultLength = FromBase64_ComputeResultLength(charsPtr, chars.Length);
Debug.Assert(resultLength >= 0);
return false;
}
- fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference())
+ fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
{
bytesWritten = FromBase64_Decode(charsPtr, chars.Length, bytesPtr, bytes.Length);
return true;
using System.Reflection;
using System.Diagnostics;
+using System.Runtime.InteropServices;
using System.Runtime.Serialization;
namespace System.Globalization
int length = Math.Min(strA.Length, strB.Length);
int range = length;
- fixed (char* ap = &strA.DangerousGetPinnableReference())
- fixed (char* bp = &strB.DangerousGetPinnableReference())
+ fixed (char* ap = &MemoryMarshal.GetReference(strA))
+ fixed (char* bp = &MemoryMarshal.GetReference(strB))
{
char* a = ap;
char* b = bp;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+
using Internal.Runtime.CompilerServices;
namespace System
unsafe
{
- fixed (char* guidChars = &destination.DangerousGetPinnableReference())
+ fixed (char* guidChars = &MemoryMarshal.GetReference(destination))
{
char * p = guidChars;
using Microsoft.Win32.SafeHandles;
using System.Diagnostics;
+using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
VerifyOSHandlePosition();
int bytesRead;
- fixed (byte* bufPtr = &buffer.DangerousGetPinnableReference())
+ fixed (byte* bufPtr = &MemoryMarshal.GetReference(buffer))
{
bytesRead = CheckFileCall(Interop.Sys.Read(_fileHandle, bufPtr, buffer.Length));
Debug.Assert(bytesRead <= buffer.Length);
{
VerifyOSHandlePosition();
- fixed (byte* bufPtr = &source.DangerousGetPinnableReference())
+ fixed (byte* bufPtr = &MemoryMarshal.GetReference(source))
{
int offset = 0;
int count = source.Length;
Debug.Assert(_useAsyncIO, "WriteInternalCoreAsync doesn't work on synchronous file streams!");
// Create and store async stream class library specific data in the async result
- FileStreamCompletionSource completionSource = source.DangerousTryGetArray(out ArraySegment<byte> array) ?
+ FileStreamCompletionSource completionSource = MemoryMarshal.TryGetArray(source, out ArraySegment<byte> array) ?
new FileStreamCompletionSource(this, 0, array.Array) :
new MemoryFileStreamCompletionSource(this, 0, source);
NativeOverlapped* intOverlapped = completionSource.Overlapped;
int r;
int numBytesRead = 0;
- fixed (byte* p = &bytes.DangerousGetPinnableReference())
+ fixed (byte* p = &MemoryMarshal.GetReference(bytes))
{
r = _useAsyncIO ?
Interop.Kernel32.ReadFile(handle, p, bytes.Length, IntPtr.Zero, overlapped) :
int numBytesWritten = 0;
int r;
- fixed (byte* p = &buffer.DangerousGetPinnableReference())
+ fixed (byte* p = &MemoryMarshal.GetReference(buffer))
{
r = _useAsyncIO ?
Interop.Kernel32.WriteFile(handle, p, buffer.Length, IntPtr.Zero, overlapped) :
internal MemoryFileStreamCompletionSource(FileStream stream, int numBufferedBytes, ReadOnlyMemory<byte> memory) :
base(stream, numBufferedBytes, bytes: null) // this type handles the pinning, so null is passed for bytes
{
- Debug.Assert(!memory.DangerousTryGetArray(out ArraySegment<byte> array), "The base should be used directly if we can get the array.");
+ Debug.Assert(!MemoryMarshal.TryGetArray(memory, out ArraySegment<byte> array), "The base should be used directly if we can get the array.");
_handle = memory.Retain(pin: true);
}
using System.Diagnostics;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
{
// See corresponding comment in ReadAsync for why we don't just always use Write(ReadOnlySpan<byte>).
// Unlike ReadAsync, we could delegate to WriteAsync(byte[], ...) here, but we don't for consistency.
- if (source.DangerousTryGetArray(out ArraySegment<byte> sourceArray))
+ if (MemoryMarshal.TryGetArray(source, out ArraySegment<byte> sourceArray))
{
Write(sourceArray.Array, sourceArray.Offset, sourceArray.Count);
}
unsafe
{
- fixed (byte* pBuffer = &destination.DangerousGetPinnableReference())
+ fixed (byte* pBuffer = &MemoryMarshal.GetReference(destination))
{
if (_buffer != null)
{
}
}
- fixed (byte* pBuffer = &source.DangerousGetPinnableReference())
+ fixed (byte* pBuffer = &MemoryMarshal.GetReference(source))
{
if (_buffer != null)
{
{
// See corresponding comment in ReadAsync for why we don't just always use Write(ReadOnlySpan<byte>).
// Unlike ReadAsync, we could delegate to WriteAsync(byte[], ...) here, but we don't for consistency.
- if (source.DangerousTryGetArray(out ArraySegment<byte> sourceArray))
+ if (MemoryMarshal.TryGetArray(source, out ArraySegment<byte> sourceArray))
{
Write(sourceArray.Array, sourceArray.Offset, sourceArray.Count);
}
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
+using System.Runtime.InteropServices;
namespace System
{
// https://devdiv.visualstudio.com/DevDiv/_workitems?id=286592
get
{
- if (_memory.DangerousTryGetArray(out ArraySegment<T> segment))
+ if (MemoryMarshal.TryGetArray(_memory, out ArraySegment<T> segment))
{
T[] array = new T[_memory.Length];
Array.Copy(segment.Array, segment.Offset, array, 0, array.Length);
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using System.Text;
namespace System
scaleAdjust = 0;
src = section;
- fixed (char* pFormat = &format.DangerousGetPinnableReference())
+ fixed (char* pFormat = &MemoryMarshal.GetReference(format))
{
while (src < format.Length && (ch = pFormat[src++]) != 0 && ch != ';')
{
bool decimalWritten = false;
- fixed (char* pFormat = &format.DangerousGetPinnableReference())
+ fixed (char* pFormat = &MemoryMarshal.GetReference(format))
{
char* cur = dig;
int digitCount = 0;
int digLength = string.wcslen(dig);
int digStart = (digPos < digLength) ? digPos : digLength;
- fixed (char* spanPtr = &sb.AppendSpan(bufferSize).DangerousGetPinnableReference())
+ fixed (char* spanPtr = &MemoryMarshal.GetReference(sb.AppendSpan(bufferSize)))
{
char* p = spanPtr + bufferSize - 1;
for (int i = digPos - 1; i >= 0; i--)
if (section == 0)
return 0;
- fixed (char* pFormat = &format.DangerousGetPinnableReference())
+ fixed (char* pFormat = &MemoryMarshal.GetReference(format))
{
src = 0;
for (;;)
using System.Diagnostics;
using System.Globalization;
+using System.Runtime.InteropServices;
namespace System
{
private static unsafe void StringToNumber(ReadOnlySpan<char> str, NumberStyles options, ref NumberBuffer number, NumberFormatInfo info, bool parseDecimal)
{
Debug.Assert(info != null);
- fixed (char* stringPointer = &str.DangerousGetPinnableReference())
+ fixed (char* stringPointer = &MemoryMarshal.GetReference(str))
{
char* p = stringPointer;
if (!ParseNumber(ref p, options, ref number, info, parseDecimal)
internal static unsafe bool TryStringToNumber(ReadOnlySpan<char> str, NumberStyles options, ref NumberBuffer number, NumberFormatInfo numfmt, bool parseDecimal)
{
Debug.Assert(numfmt != null);
- fixed (char* stringPointer = &str.DangerousGetPinnableReference())
+ fixed (char* stringPointer = &MemoryMarshal.GetReference(str))
{
char* p = stringPointer;
if (!ParseNumber(ref p, options, ref number, numfmt, parseDecimal)
using System.Text;
using System;
using System.Diagnostics;
+using System.Runtime.InteropServices;
namespace System.Text
{
public virtual unsafe int GetCharCount(ReadOnlySpan<byte> bytes, bool flush)
{
- fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference())
+ fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
{
return GetCharCount(bytesPtr, bytes.Length, flush);
}
public virtual unsafe int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars, bool flush)
{
- fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference())
- fixed (char* charsPtr = &chars.DangerousGetPinnableReference())
+ fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
+ fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
{
return GetChars(bytesPtr, bytes.Length, charsPtr, chars.Length, flush);
}
public virtual unsafe void Convert(ReadOnlySpan<byte> bytes, Span<char> chars, bool flush, out int bytesUsed, out int charsUsed, out bool completed)
{
- fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference())
- fixed (char* charsPtr = &chars.DangerousGetPinnableReference())
+ fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
+ fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
{
Convert(bytesPtr, bytes.Length, charsPtr, chars.Length, flush, out bytesUsed, out charsUsed, out completed);
}
using System.Text;
using System;
using System.Diagnostics;
+using System.Runtime.InteropServices;
namespace System.Text
{
public virtual unsafe int GetByteCount(ReadOnlySpan<char> chars, bool flush)
{
- fixed (char* charsPtr = &chars.DangerousGetPinnableReference())
+ fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
{
return GetByteCount(charsPtr, chars.Length, flush);
}
public virtual unsafe int GetBytes(ReadOnlySpan<char> chars, Span<byte> bytes, bool flush)
{
- fixed (char* charsPtr = &chars.DangerousGetPinnableReference())
- fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference())
+ fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
+ fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
{
return GetBytes(charsPtr, chars.Length, bytesPtr, bytes.Length, flush);
}
public virtual unsafe void Convert(ReadOnlySpan<char> chars, Span<byte> bytes, bool flush, out int charsUsed, out int bytesUsed, out bool completed)
{
- fixed (char* charsPtr = &chars.DangerousGetPinnableReference())
- fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference())
+ fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
+ fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
{
Convert(charsPtr, chars.Length, bytesPtr, bytes.Length, flush, out charsUsed, out bytesUsed, out completed);
}
using System.Diagnostics;
using System.Globalization;
using System.Threading;
+using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Diagnostics.CodeAnalysis;
public virtual unsafe int GetByteCount(ReadOnlySpan<char> chars)
{
- fixed (char* charsPtr = &chars.DangerousGetPinnableReference())
+ fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
{
return GetByteCount(charsPtr, chars.Length);
}
public virtual unsafe int GetBytes(ReadOnlySpan<char> chars, Span<byte> bytes)
{
- fixed (char* charsPtr = &chars.DangerousGetPinnableReference())
- fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference())
+ fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
+ fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
{
return GetBytes(charsPtr, chars.Length, bytesPtr, bytes.Length);
}
public virtual unsafe int GetCharCount(ReadOnlySpan<byte> bytes)
{
- fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference())
+ fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
{
return GetCharCount(bytesPtr, bytes.Length);
}
public virtual unsafe int GetChars(ReadOnlySpan<byte> bytes, Span<char> chars)
{
- fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference())
- fixed (char* charsPtr = &chars.DangerousGetPinnableReference())
+ fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
+ fixed (char* charsPtr = &MemoryMarshal.GetReference(chars))
{
return GetChars(bytesPtr, bytes.Length, charsPtr, chars.Length);
}
public unsafe string GetString(ReadOnlySpan<byte> bytes)
{
- fixed (byte* bytesPtr = &bytes.DangerousGetPinnableReference())
+ fixed (byte* bytesPtr = &MemoryMarshal.GetReference(bytes))
{
return GetString(bytesPtr, bytes.Length);
}
using System.Runtime.Serialization;
using System;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Threading;
{
unsafe
{
- fixed (char* valueChars = &value.DangerousGetPinnableReference())
+ fixed (char* valueChars = &MemoryMarshal.GetReference(value))
{
Append(valueChars, value.Length);
}
{
unsafe
{
- fixed (char* sourcePtr = &value.DangerousGetPinnableReference())
+ fixed (char* sourcePtr = &MemoryMarshal.GetReference(value))
Insert(index, sourcePtr, value.Length);
}
}
}
fixed (char* sourcePtr = &source[sourceIndex])
- fixed (char* destinationPtr = &destination.DangerousGetPinnableReference())
+ fixed (char* destinationPtr = &MemoryMarshal.GetReference(destination))
string.wstrcpy(destinationPtr + destinationIndex, sourcePtr, count);
}
}
internal static unsafe int GetSystemDirectoryW(Span<char> buffer)
{
- fixed (char* bufferPtr = &buffer.DangerousGetPinnableReference())
+ fixed (char* bufferPtr = &MemoryMarshal.GetReference(buffer))
{
return GetSystemDirectoryW(bufferPtr, buffer.Length);
}
internal static unsafe int GetEnvironmentVariable(string lpName, Span<char> lpValue)
{
- fixed (char* lpValuePtr = &lpValue.DangerousGetPinnableReference())
+ fixed (char* lpValuePtr = &MemoryMarshal.GetReference(lpValue))
{
return GetEnvironmentVariable(lpName, lpValuePtr, lpValue.Length);
}
Debug.Assert(string2 != null);
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
- fixed (char* pString1 = &string1.DangerousGetPinnableReference())
+ fixed (char* pString1 = &MemoryMarshal.GetReference(string1))
fixed (char* pString2 = &string2.GetRawStringData())
{
return Interop.GlobalizationInterop.CompareString(_sortHandle, pString1, string1.Length, pString2, string2.Length, options);
Debug.Assert(!_invariantMode);
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
- fixed (char* pString1 = &string1.DangerousGetPinnableReference())
- fixed (char* pString2 = &string2.DangerousGetPinnableReference())
+ fixed (char* pString1 = &MemoryMarshal.GetReference(string1))
+ fixed (char* pString2 = &MemoryMarshal.GetReference(string2))
{
return Interop.GlobalizationInterop.CompareString(_sortHandle, pString1, string1.Length, pString2, string2.Length, options);
}
string localeName = _sortHandle != IntPtr.Zero ? null : _sortName;
fixed (char* pLocaleName = localeName)
- fixed (char* pString1 = &string1.DangerousGetPinnableReference())
+ fixed (char* pString1 = &MemoryMarshal.GetReference(string1))
fixed (char* pString2 = &string2.GetRawStringData())
{
int result = Interop.Kernel32.CompareStringEx(
string localeName = _sortHandle != IntPtr.Zero ? null : _sortName;
fixed (char* pLocaleName = localeName)
- fixed (char* pString1 = &string1.DangerousGetPinnableReference())
- fixed (char* pString2 = &string2.DangerousGetPinnableReference())
+ fixed (char* pString1 = &MemoryMarshal.GetReference(string1))
+ fixed (char* pString2 = &MemoryMarshal.GetReference(string2))
{
int result = Interop.Kernel32.CompareStringEx(
pLocaleName,
using System;
using System.Runtime;
+using System.Runtime.InteropServices;
using System.Text;
using System.Globalization;
using System.Diagnostics;
unsafe
{
fixed (byte* pBytes = byteBuffer)
- fixed (char* pChars = &buffer.DangerousGetPinnableReference())
+ fixed (char* pChars = &MemoryMarshal.GetReference(buffer))
{
charsRead = _decoder.GetChars(pBytes + position, numBytes, pChars + index, charsRemaining, flush: false);
}
public virtual Task WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default(CancellationToken))
{
- if (source.DangerousTryGetArray(out ArraySegment<byte> array))
+ if (MemoryMarshal.TryGetArray(source, out ArraySegment<byte> array))
{
return WriteAsync(array.Array, array.Offset, array.Count, cancellationToken);
}
}
string result = FastAllocateString(value.Length);
- fixed (char* dest = &result._firstChar, src = &value.DangerousGetPinnableReference())
+ fixed (char* dest = &result._firstChar, src = &MemoryMarshal.GetReference(value))
{
wstrcpy(dest, src, value.Length);
}
DEFINE_METASIG(SM(RefFlt_Flt, r(f) f, v))
DEFINE_METASIG(SM(RefDbl_RetDbl, r(d), d))
DEFINE_METASIG(SM(RefDbl_Dbl, r(d) d, v))
-DEFINE_METASIG(GM(RefT_RetT, IMAGE_CEE_CS_CALLCONV_DEFAULT, 1, r(M(0)) , M(0)))
+DEFINE_METASIG(GM(RefT_RetT, IMAGE_CEE_CS_CALLCONV_DEFAULT, 1, r(M(0)), M(0)))
DEFINE_METASIG(GM(RefT_T, IMAGE_CEE_CS_CALLCONV_DEFAULT, 1, r(M(0)) M(0), v))
DEFINE_METASIG(GM(RefByte_RetT, IMAGE_CEE_CS_CALLCONV_DEFAULT, 1, r(b), M(0)))
[MethodImpl(MethodImplOptions.NoInlining)]
static byte TestRef(Span<byte> data)
{
- ref byte p = ref data.DangerousGetPinnableReference();
+ ref byte p = ref MemoryMarshal.GetReference(data);
int length = data.Length;
byte x = 0;
[MethodImpl(MethodImplOptions.NoInlining)]
static unsafe byte TestFixed1(Span<byte> data)
{
- fixed (byte* pData = &data.DangerousGetPinnableReference())
+ fixed (byte* pData = &MemoryMarshal.GetReference(data))
{
int length = data.Length;
byte x = 0;
[MethodImpl(MethodImplOptions.NoInlining)]
static unsafe byte TestFixed2(Span<byte> data)
{
- fixed (byte* pData = &data.DangerousGetPinnableReference())
+ fixed (byte* pData = &MemoryMarshal.GetReference(data))
{
int length = data.Length;
byte x = 0;