问题描述
是否有理由 System.Buffer.BlockCopy
使用 int
参数而不是 long
作为副本的偏移量/长度?流通常与 long
一起使用,为什么 BlockCopy
也不会具有需要 long
的重载?
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?
推荐答案
由于在.NET 4.5之前,没有对象可以超过2 GB.因此,没有理由要用一个以上的整数来表示长度.
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.
即使在.NET 4.5中,尽管数组的长度可以超过2 GB,但它不能超过2 ^ 31个项目.因此, byte []
的最大大小仍为2 GB(减去一点开销). int []
的最大大小为2 ^ 31个项目或大约8 GB,等等.请参见 gcAllowVeryLargObjects .
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.
这篇关于为什么System.Buffer.BlockCopy采用int而不是long?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!