-
I'm hoping for some guidance or "best practice" on how to implement From the latter, one could assume that the buffer remains unchanged in such a case. However, that's not guaranteed to be true. I looked at the various implementations in the runtime. A lot of them go to great lengths to determine the required size beforehand and only write to the destination buffer if it is big enough. Others, particularly when using These differences may have historical reasons, the attitude may have changed over time, or it may be merely a question of how costly the extra step of pre-calculating the required size is. Some clarification and currently recommended best practice on this matter would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I believe our current stance for a Span-based TryWrite is "any part of the buffer between If TryWrite returns false it's supposed to out |
Beta Was this translation helpful? Give feedback.
-
Thanks for the responses. So those implementations in the runtime that go out of their way to determine if the destination buffer is suitable before writing to it can be chalked up to... different times? individual code style? |
Beta Was this translation helpful? Give feedback.
I believe our current stance for a Span-based TryWrite is "any part of the buffer between
written
andLength
should be assumed to be garbage on the part of a caller". So if you pass in a 100-item span, and it says it wrote 5,[5]
isn't guaranteed unchanged, it might have been used for an intermediate calculation.If TryWrite returns false it's supposed to out
written
as 0, in which case the whole of the destination buffer should be assumed garbage.