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
Productizing APIs for {ReadOnly}Memory<T> and friends #23480
Comments
public static implicit operator Memory<T>(ArraySegment<T> arraySegment);
public static implicit operator ReadOnlyMemory<T>(Memory<T> memory);
public static implicit operator ReadOnlyMemory<T>(ArraySegment<T> arraySegment); Are these the only ways to convert from
Specifically, F# does not support implicit operators, but allows calling them as let memoryToReadOnlyMemory (memory : Memory<'a>) : ReadOnlyMemory<'a> =
Memory<'a>.op_Implicit memory For the |
…3701) * Adding Memory, OwnedMemory, MemoryHandle, and IRetainable * Adding initial tests and fixing Memory.Empty property * Adding {RO}Memory tests and fixing XML comments based on feedback. * Removing netstandard1.0 build configuration and adding netstandard1.1. * Fixing errors in the upgrade from netstandard1.0 to netstandard1.1. * Removing Windows Phone 8 as a supported framework for System.Memory package.
I have added the following extension methods (analogous methods exist for Span) to the proposal for review: - public static Memory<T> AsMemory<T>(this T[] array);
- public static Memory<T> AsMemory<T>(this ArraySegment<T> arraySegment);
- public static ReadOnlyMemory<T> AsReadOnlyMemory<T>(this T[] array);
- public static ReadOnlyMemory<T> AsReadOnlyMemory<T>(this ArraySegment<T> arraySegment);
The same issue occurs for Span to ReadOnlySpan (since only an implicit conversion is available). Can you please file a separate issue regarding this for both types? |
@ahsonkhan mentioned he's not ready for a review yet. |
The Here is what we need to discuss.
// instance methods
public struct Memory<T> {
public void CopyTo(Memory<T> destination);
public bool TryCopyTo(Memory<T> destination);
public void Fill(T value);
public void Clear();
}
public struct ReadOnlyMemory<T> {
public void CopyTo(Memory<T> destination);
public bool TryCopyTo(Memory<T> destination);
}
// extension methods
public static class MemoryExtensions {
public static int IndexOf<T>(this Memory<T> memory, T value);
public static int IndexOf<T>(this Memory<T> memory, ReadOnlyMemory<T> value);
public static int IndexOf<T>(this ReadOnlyMemory<T> memory, T value);
public static int IndexOf<T>(this ReadOnlyMemory<T> memory, ReadOnlyMemory<T> value);
public static bool SequenceEqual<T>(this Memory<T> first, ReadOnlyMemory<T> second);
public static bool SequenceEqual<T>(this ReadOnlyMemory<T> first, ReadOnlyMemory<T> second);
public static void CopyTo<T>(this T[] array, Memory<T> destination);
public static Memory<T> AsMemory<T>(this T[] array);
public static Memory<T> AsMemory<T>(this ArraySegment<T> arraySegment);
public static ReadOnlyMemory<T> AsReadOnlyMemory<T>(this T[] array);
public static ReadOnlyMemory<T> AsReadOnlyMemory<T>(this ArraySegment<T> arraySegment);
} |
We don't want to add the bulk methods. We believe it could become a performance trap and it invites having to keep // instance methods
public struct Memory<T> {
public void CopyTo(Memory<T> destination);
public bool TryCopyTo(Memory<T> destination);
}
public struct ReadOnlyMemory<T> {
public void CopyTo(Memory<T> destination);
public bool TryCopyTo(Memory<T> destination);
}
// extension methods
// Merge with SpanExtensions
public static class MemoryExtensions {
public static void CopyTo<T>(this T[] array, Memory<T> destination);
} We should probably rename |
FYI: The API review discussion was recorded - see https://youtu.be/bHwCPVNQLwo?t=333 (37 min duration) |
Open issues to resolve as part of productizing:
Here are the Memory APIs that have already gone through API review
They were added here:
(https://github.com/dotnet/corefx/blob/master/src/System.Memory/ref/System.Memory.cs#L149)
cc @weshaggard, @KrzysztofCwalina, @shiftylogic, @stephentoub, @terrajobst, @karelz, @jkotas, @davidfowl
The text was updated successfully, but these errors were encountered: