dotnet / dotnet/dotnet-api-docs
ArrayPool<T>.Create missing limits
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
[`ArrayPool.Create(int maxArrayLength, int maxArraysPerBucket)`](https://learn.microsoft.com/en-gb/dotnet/api/system.buffers.arraypool-1.create?view=net-8.0#system-buffers-arraypool-1-create(system-int32-system-int32))
This documentation makes no mention of any limits on the `maxArrayLength` parameter. Whilst the fact that this parameter cannot be less than or equal to zero is *(probably)* self-evident, [the source code](https://github.com/dotnet/runtime/blob/346706614bc9e3345906c4696106c554602e9bf6/src/libraries/System.Private.CoreLib/src/System/Buffers/ConfigurableArrayPool.cs#L27) reveals a further undocumented limit:
> Our bucketing algorithm has a min length of `2^4` and a max length of `2^30`. Constrain the actual max used to those values.
This limitation should be included in the documentation to avoid confusion, as seen in [this Reddit post](https://www.reddit.com/r/csharp/comments/194s4e8/arraypoolcreate_unexpected_behaviour/).
Contributor guide
Assessment
This issue has not been assessed yet.