Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for SafeBuffer.ReadSpan/WriteSpan #54942

Merged
merged 3 commits into from
Jul 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
**
===========================================================*/
Expand Down Expand Up @@ -203,6 +203,13 @@ public T Read<T>(ulong byteOffset) where T : struct
return value;
}

/// <summary>
/// Reads the specified number of value types from memory starting at the offset, and writes them into an array starting at the index.</summary>
/// <typeparam name="T">The value type to read.</typeparam>
/// <param name="byteOffset">The location from which to start reading.</param>
/// <param name="array">The output array to write to.</param>
/// <param name="index">The location in the output array to begin writing to.</param>
/// <param name="count">The number of value types to read from the input array and to write to the output array.</param>
[CLSCompliant(false)]
public void ReadArray<T>(ulong byteOffset, T[] array, int index, int count)
where T : struct
Expand All @@ -219,6 +226,11 @@ public void ReadArray<T>(ulong byteOffset, T[] array, int index, int count)
ReadSpan(byteOffset, new Span<T>(array, index, count));
}

/// <summary>
/// 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.</summary>
/// <typeparam name="T">The value type to read.</typeparam>
/// <param name="byteOffset">The location from which to start reading.</param>
/// <param name="buffer">The output span to write to.</param>
[CLSCompliant(false)]
public void ReadSpan<T>(ulong byteOffset, Span<T> buffer)
where T : struct
Expand Down Expand Up @@ -279,6 +291,14 @@ public void Write<T>(ulong byteOffset, T value) where T : struct
}
}

/// <summary>
/// Writes the specified number of value types to a memory location by reading bytes starting from the specified location in the input array.
/// </summary>
/// <typeparam name="T">The value type to write.</typeparam>
/// <param name="byteOffset">The location in memory to write to.</param>
/// <param name="array">The input array.</param>
/// <param name="index">The offset in the array to start reading from.</param>
/// <param name="count">The number of value types to write.</param>
[CLSCompliant(false)]
public void WriteArray<T>(ulong byteOffset, T[] array, int index, int count)
where T : struct
Expand All @@ -295,6 +315,12 @@ public void WriteArray<T>(ulong byteOffset, T[] array, int index, int count)
WriteSpan(byteOffset, new ReadOnlySpan<T>(array, index, count));
}

/// <summary>
/// Writes the value types from a read-only span to a memory location.
/// </summary>
/// <typeparam name="T">The value type to write.</typeparam>
/// <param name="byteOffset">The location in memory to write to.</param>
/// <param name="data">The input span.</param>
[CLSCompliant(false)]
public void WriteSpan<T>(ulong byteOffset, ReadOnlySpan<T> data)
where T : struct
Expand Down