diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeBuffer.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeBuffer.cs index 8f7eee8c448d7..3e7f204573ca0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeBuffer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeBuffer.cs @@ -4,7 +4,7 @@ /*============================================================ ** ** Purpose: Unsafe code that uses pointers should use -** SafePointer to fix subtle lifetime problems with the +** SafeBuffer to fix subtle lifetime problems with the ** underlying resource. ** ===========================================================*/ @@ -203,6 +203,13 @@ public T Read(ulong byteOffset) where T : struct return value; } + /// + /// Reads the specified number of value types from memory starting at the offset, and writes them into an array starting at the index. + /// The value type to read. + /// The location from which to start reading. + /// The output array to write to. + /// The location in the output array to begin writing to. + /// The number of value types to read from the input array and to write to the output array. [CLSCompliant(false)] public void ReadArray(ulong byteOffset, T[] array, int index, int count) where T : struct @@ -219,6 +226,11 @@ public void ReadArray(ulong byteOffset, T[] array, int index, int count) ReadSpan(byteOffset, new Span(array, index, count)); } + /// + /// Reads value types from memory starting at the offset, and writes them into a span. The number of value types that will be read is determined by the length of the span. + /// The value type to read. + /// The location from which to start reading. + /// The output span to write to. [CLSCompliant(false)] public void ReadSpan(ulong byteOffset, Span buffer) where T : struct @@ -279,6 +291,14 @@ public void Write(ulong byteOffset, T value) where T : struct } } + /// + /// Writes the specified number of value types to a memory location by reading bytes starting from the specified location in the input array. + /// + /// The value type to write. + /// The location in memory to write to. + /// The input array. + /// The offset in the array to start reading from. + /// The number of value types to write. [CLSCompliant(false)] public void WriteArray(ulong byteOffset, T[] array, int index, int count) where T : struct @@ -295,6 +315,12 @@ public void WriteArray(ulong byteOffset, T[] array, int index, int count) WriteSpan(byteOffset, new ReadOnlySpan(array, index, count)); } + /// + /// Writes the value types from a read-only span to a memory location. + /// + /// The value type to write. + /// The location in memory to write to. + /// The input span. [CLSCompliant(false)] public void WriteSpan(ulong byteOffset, ReadOnlySpan data) where T : struct