Add ArrayPool<T>.RentOwner() extension returning IMemoryOwner<T>#23
Merged
Add ArrayPool<T>.RentOwner() extension returning IMemoryOwner<T>#23
Conversation
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/0af65137-32fa-448b-bfd8-1773ca877813 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/0af65137-32fa-448b-bfd8-1773ca877813 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
Tyrrrz
April 14, 2026 15:44
View session
Tyrrrz
approved these changes
Apr 14, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an ArrayPool<T> extension that enables using-style ownership (IMemoryOwner<T>) for rented arrays, aligning the ergonomics with MemoryPool<T> usage patterns in the codebase.
Changes:
- Introduces
ArrayPool<T>.RentOwner(int minimumLength = 1)that returns anIMemoryOwner<T>and returns the rented array on dispose. - Slices
Memoryto exactlyminimumLengthelements (even if a larger array is rented). - Adds unit tests for
Memory.Lengthand dispose behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| PowerKit/Extensions/ArrayPoolExtensions.cs | Adds RentOwner() and an IMemoryOwner<T> implementation that returns arrays to ArrayPool<T> on disposal. |
| PowerKit.Tests/ArrayPoolExtensionsTests.cs | Adds tests covering the new RentOwner() API shape and intended dispose semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
… use Interlocked for thread-safe dispose guard Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/1c6ae2f7-27ef-4c05-9ae4-8ece85ee42c7 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Tyrrrz
reviewed
Apr 14, 2026
…Dispose_Test Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/13075def-164e-4e3b-9237-749e857bdb46 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
This was referenced May 1, 2026
This was referenced May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ArrayPool<T>lacks theIDisposable-based ownership pattern thatMemoryPool<T>provides, making it awkward to use inusingscopes without manualReturn()calls.Changes
ArrayPoolExtensions.cs: addsRentOwner(int minimumLength = 1)extension onArrayPool<T>, returning anIMemoryOwner<T>that returns the buffer to the pool on dispose.Memory.Lengthis sliced to exactlyminimumLength, matchingMemoryPool<T>semantics. Disposal is idempotent.ArrayPoolExtensionsTests.cs: tests for correctMemory.Lengthand buffer return on dispose.Usage