Runtime: Consider documenting the initial contents of the Span<char> passed into SpanAction of string.Create method

Created on 21 Mar 2020  路  12Comments  路  Source: dotnet/runtime

Looking at the documents It is currently unclear on whether the contents are zeroed or contain random data. I believe currently the contents are zeroed (returned from FastAllocateString) but it would be nice to specify whether it is something people can rely on or not.

area-System.Runtime documentation untriaged

Most helpful comment

It's completely not guaranteed, you're responsible for assigning every position

Yes, it would be a good idea to mention this in the documentation.

could it be a breaking change if we were to change its implementation to give non-zeroed string

We would not change this in servicing where we try to maintain bug-for-bug compatibility. I believe that we would be comfortable to change it for major version where we try to be compatible, but not bug-for-bug compatible.

All 12 comments

I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label.

I believe the answer is "it's completely not guaranteed, you're responsible for assigning every position"

I did guess so. However could it be a breaking change if we were to change its implementation to give non-zeroed string? It has not been documented so far and currently it zeroes. It wouldn't have been a breaking change if it were documented to suggest it could contain gibberish data (like stackalloc etc) when it was first introduced.

@jkotas would it be reasonable to document this?

It's completely not guaranteed, you're responsible for assigning every position

Yes, it would be a good idea to mention this in the documentation.

could it be a breaking change if we were to change its implementation to give non-zeroed string

We would not change this in servicing where we try to maintain bug-for-bug compatibility. I believe that we would be comfortable to change it for major version where we try to be compatible, but not bug-for-bug compatible.

Great! I can put up a PR on the docs repo in the morning (local time).

Though, do I need to make two separate PRs (one in the docs repo, one in the runtime repo), or do the changes made in XML comments propagate down to the dotnet-api-docs repo?

The XML comments and the docs repo are not kept in sync automatically. It has to be done manually.

I'd just do it in Remarks on the docs site, I wouldn't do anything here.

@jkotas So zero-init memory is guaranteed here for 2.1-5.0?

It always happens to zero-init in 2.1 - 3.1. We have not shipped 5.0 yet...

We should document that it's not guaranteed. I believe that's what Jan is saying as well. Correct, Jan?

Right. The docs should not mention that it happens to zero-init in 2.1 - 3.1

Somehow I decided Jan had quoted the "it's zero" instead of my "it's not guaranteed". Good clarification.

Was this page helpful?
0 / 5 - 0 ratings