问题
Is there a reason System.Buffer.BlockCopy
takes int
parameters instead of long
for the offset/length of the copy? Streams generally work with long
, why would BlockCopy
not have an overload that takes long
, too?
回答1:
Because prior to .NET 4.5, no object could exceed 2 gigabytes. So there was no reason to have more than an int to represent the length.
Even in .NET 4.5, although an array can be more than 2 gigabytes in length, it can't have more than 2^31 items. So the maximum size of a byte[]
is still 2 gigabytes (minus a little overhead). The maximum size of an int[]
is 2^31 items or about 8 gigabytes, etc. See gcAllowVeryLargObjects.
来源:https://stackoverflow.com/questions/15487546/why-does-system-buffer-blockcopy-take-int-instead-of-long