-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Proposal: MemoryPool.RentExact() returns IMemoryOwner with pre-sliced Memory #30165
Comments
I'm a little confused. If you already have a variable for "actual length of the data", then doesn't that mean that you already have data in some |
I assume it means; |
@GrabYourPitchforks in my case I have a PipeReader and I know that I will read n continuous bytes then pass them upstream for further processing. |
I'd also like something like this. In my case, I'm reading a length-prefixed string from a SequenceReader, which is passed elsewhere for processing. |
Yes please - it is so so so frustrating having to pass around extra data, half the point of memory is not having to do that :| |
I looked through #27869 but I don't see how the What am I missing? Is there a code sample that clearly shows the benefit of having this new proposed API? |
I also think the RentExact API would be a good addition. Also with an optional boolean parameter(if the returned pre-sliced memory should be cleared when disposed, only the pre-sliced range should be cleared) Lets say you have a complete json object in a ReadOnlySequence. To parse this you could do something like this: Code just for example:
If the optional clearOnDispose parameter on RentExact is available the last try/finally would be unnecessary. Same sample with RentExact API with clearOnDispose option.
|
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process. This process is part of our issue cleanup automation. |
I found it really disappointing that MemoryPool.Rent behaves as ArrayPool and can return Memory that is larger then what I want - it makes sense for arrays but Memory could be easily pre-sliced to required size - this will most importantly allow passing this IMemoryOwner to outside code without the need to pass along another variable indicating the actual length of the data and slicing the underling memory every time you want to access it. This could even allow to have more efficient MemoryPool implementation which could rent several IMemoryOwners from the same block of memory. It would also be a lot simpler to implement then #27869 (but it is not mutually exclusive).
The text was updated successfully, but these errors were encountered: