Skip to content

Fix: ArrayPool<T>.Rent can return array longer than minimumLength#96

Merged
neuecc merged 1 commit into
Cysharp:masterfrom
0xfeeddeadbeef:bugfix/arraypool
Jul 28, 2025
Merged

Fix: ArrayPool<T>.Rent can return array longer than minimumLength#96
neuecc merged 1 commit into
Cysharp:masterfrom
0xfeeddeadbeef:bugfix/arraypool

Conversation

@0xfeeddeadbeef
Copy link
Copy Markdown
Contributor

It should not be assumed that the returned array will be exactly the length requested.

For example, if you run this script using Windows PowerShell, eventually red messages will start appearing:

using assembly "C:\Users\UserName\.nuget\system.buffers\4.4.0\lib\netstandard2.0\System.Buffers.dll"

foreach ($i in 1..300000) {
  $a = [System.Buffers.ArrayPool[byte]]::Shared.Rent(16)
  if ($a.Length -ne 16) {
    Write-Host "Rented larger than minimumLength: $($a.Length)" -ForegroundColor Red
  }
}

@neuecc
Copy link
Copy Markdown
Member

neuecc commented Jul 28, 2025

Thank you, this is a correct and important point!

@neuecc neuecc merged commit a356907 into Cysharp:master Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants