-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Avoid empty segments from PipeReader.ReadAsync #72536
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
Conversation
| } | ||
|
|
||
| public void ResetMemory() | ||
| public void ResetMemory(bool preserveIndex = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
Maybe add a ClearMemory() method and rename this to Reset() and have it call ClearMemory(). Because this is doing more than just resetting memory, it's resetting the RunningIndex and the _next pointer too. It might make sense for ClearMemory() to keep the ResetMemory() name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I was thinking along those lines when writing it. Good to know we're thinking that same thing.
| return newSegment; | ||
| } | ||
|
|
||
| private void SetupSegment(BufferSegment segment, int sizeHint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
| private void SetupSegment(BufferSegment segment, int sizeHint) | |
| private void RentMemory(BufferSegment segment, int sizeHint) |
| } | ||
|
|
||
| BufferSegment newSegment = AllocateSegment(sizeHint); | ||
| if (_writingHead.Length == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use _writingHeadBytesBuffered instead (but the logic would need to be reworked a bit)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I tried using that field initially, but it gets set to 0 in Advance with a non-zero value, so you need to check some other value anyways. What's wrong with _writingHead.Length?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing wrong with it, it just avoids the indirection but this is fine.
|
Both test failures have tracking issues and are unrelated to this change, merging. |
Fixes #30786
Reuses a
BufferSegmentif it is unused and a larger memory buffer is requested.There was already a memory pool test for this type of scenario, so I haven't added a new one.