-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
MemoryPool<byte>.Shared.MaxBufferSize seems incorrect #61560
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @GrabYourPitchforks, @dotnet/area-system-buffers Issue DetailsDescriptionI've found that System.MemoryPool.Shared.MaxBufferSize seems to be incorrect (at least on my computer). It claims that the max is int.MaxValue, but really the limit seems to be 56 bytes less than that. I believe that this is probably related to the fact that the same maximum seems to apply to the length of a directly-newed-up byte array (again, at least on my computer). This is using .Net 5 on a Windows 10 computer with plenty of memory. I have not tried any other versions of .Net or any other computers. Reproduction Steps
Expected behaviorI expect that the rental should succeed in all cases when I supply a number less than MaxBufferSize. I imagine (but don't know for sure that I should expect) that the raw array allocation should work if and only if the rental of the same size works. So, I expect the output to be the following, with the possible exception that "Array: xxx" might in some cases be False rather than True.
Actual behaviorInstead, both the rental and the new byte[] fail unless the length is at most 56 bytes less than MaxBufferSize:
Regression?Sorry, I have no idea. Known WorkaroundsI dunno, manually make sure you're trying within the experimentally-determined "real" limit, I guess? Configuration
Other informationAs mentioned above, I believe that this is probably related to the fact that the same maximum seems to apply to the length of a directly-newed-up byte array (again, at least on my computer).
|
`ArrayMemoryPool.MaxBufferSize`'s value was changed to `Array.MaxLength`.
That assumption is not valid. Per MSDN:
If you look at consumers of I'm torn on whether we should change the implementation of this property, considering that |
Having a property to say that "this int must be less than or equal to the maximum possible value of an int, but that's not a promise that any int less than or equal to it will work" seems, as you said, pointless. Why not have it on every interface? "The length of a string is an int. That int must be less than or equal to the maximum possible value of an int. However, that's not to say that the length of a string can be that long. In fact there is no guarantee that there is any int that is a valid length for a string. Not even zero." Its mere existence is misleading even if it is technically correct. |
It's an abstract member of the base class, and there are legitimate reasons for an implementation to say "I have constraints." aspnet's pool is a prime example. The |
Yes, I understand that there are legitimate reasons for an implementation to say that it has constraints. What I guess I don't understand is why this implementation doesn't. It seems to me that the implementation is not limitless. That some theoretical different implementation might have a greater limit seems like it's neither here nor there with respect to that. |
Description
I've found that System.MemoryPool.Shared.MaxBufferSize seems to be incorrect (at least on my computer). It claims that the max is int.MaxValue, but really the limit seems to be 56 bytes less than that. I believe that this is probably related to the fact that the same maximum seems to apply to the length of a directly-newed-up byte array (again, at least on my computer).
This is using .Net 5 on a Windows 10 computer with plenty of memory. I have not tried any other versions of .Net or any other computers.
Reproduction Steps
Expected behavior
I expect that the rental should succeed in all cases when I supply a number less than MaxBufferSize. I imagine (but don't know for sure that I should expect) that the raw array allocation should work if and only if the rental of the same size works. So, I expect the output to be the following, with the possible exception that "Array: xxx" might in some cases be False rather than True.
Actual behavior
Instead, both the rental and the new byte[] fail unless the length is at most 56 bytes less than MaxBufferSize:
Regression?
Sorry, I have no idea.
Known Workarounds
I dunno, manually make sure you're trying within the experimentally-determined "real" limit, I guess?
Configuration
Other information
As mentioned above, I believe that this is probably related to the fact that the same maximum seems to apply to the length of a directly-newed-up byte array (again, at least on my computer).
The text was updated successfully, but these errors were encountered: