Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

MemoryOwner docs should have a warning about the maximum supported length

Open
#296 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
52/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale
Tech stack
csharp
Domain
documentation

Research direction

Read docs/high-performance/MemoryOwner.md and review the MemoryOwner guidance alongside the linked API behavior. Add a warning that ArrayPool.Shared supports pooled arrays only up to 2^20 elements, and explain that larger allocations should use Allocate with an appropriately sized ArrayPool. Done means the limitation and alternative are clear to readers.

Written by the indexing model from the issue text.

Description

dotnet dotnet-communitytoolkit/prod Pri2

Hi,

I'm new to the CommunityToolkit and was looking how the MemoryOwner<T> can help me to improve my code. A normal use case for me is working with monochrome camera image and therefore I need often large byte arrays. If I get the implementation right, the MemoryOwner<T> uses an ArrayPool<T> which is created from the ArrayPool<T>.Shared - but this supports only an array length up to 2^20 (1024 * 1024 = 1048576). If a larger array is reqested, it returns only a normal array:

https://github.com/dotnet/coreclr/blob/a9f3fc16483eecfc47fb79c362811d870be02249/src/System.Private.CoreLib/shared/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs#L142

                // The request was for a size too large for the pool.  Allocate an array of exactly the requested length.
                // When it's returned to the pool, we'll simply throw it away.
                buffer = GC.AllocateUninitializedArray<T>(minimumLength);

With that, most of the optimizations are gone!

Therefore, I think it is important to also clearly emphasize this point in the documentation. In this case the developer should use the Allocate method which accepts a ArrayPool<T> as an input parameter. This pool could be created with the right size.

Best regard,
Mike


Document Details

⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

Dominant language
No language data
Stars
168
Forks
135
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MicrosoftDocs/CommunityToolkit

All issues in MicrosoftDocs/CommunityToolkit

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.