Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@ahsonkhan
Copy link

@KrzysztofCwalina
Copy link
Member

KrzysztofCwalina commented Sep 9, 2017

looks good, but I think Memory<T> and ROMemory<T> should be marked as well.

@VSadov
Copy link
Member

VSadov commented Sep 9, 2017

Span needs to be readonly so that ordinarySpan.CopyTo(stackallocatedSpan) would work.

For regular structs being readonly is not functionally important. Since they cannot contain references, they do not participate in escape analysis.

That said, it is a good to have thing.
It is beneficial to mark struct readonly for perf reasons though. How much benefit will depend on the usage, but there is no downside.

On the other bug, I mentioned that threshold is the size to be > 2 or 4 pointers. I was confusing that with choice whether to use pass-by-value vs. pass-by-readonly-ref.

There are no unwanted consequences, however, in making a struct readonly (other than future compat issues if struct needs to drop readonly). Otherwise readonly struct behave exactly the same as ordinary structs and in some cases compiler can skip making defensive copies.

@stephentoub
Copy link
Member

FWIW, I expect we're going to want to go through the BCL and mark many structs as readonly if they can be.

@VSadov
Copy link
Member

VSadov commented Sep 9, 2017

Right, ordinary-->readonly is not a breaking change.
(intentionally, so that existing structs could be made readonly too)

@stephentoub stephentoub merged commit 3e32eb9 into dotnet:master Sep 9, 2017
dotnet-bot pushed a commit to dotnet/corert that referenced this pull request Sep 10, 2017
…ruct

Marking {ReadOnly}Span with IsReadOnly attribute

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
stephentoub added a commit to dotnet/corert that referenced this pull request Sep 10, 2017
…ruct

Marking {ReadOnly}Span with IsReadOnly attribute

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
@ahsonkhan ahsonkhan deleted the SpanReadOnlyStruct branch September 11, 2017 22:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants